Objet
|
MFC Objet
|
Utilisation et
rôle
|
Interaction avec les autres objets
|
---|---|---|---|
Application |
CWinApp |
Gère tous les objets de l'application |
Keeps a list of document templates |
Document template |
CDocTemplat | Creates and manages documents. |
Manages a list of views on its data. |
Document |
CDocument |
Objet pour stocker des données |
Manages a list of views on its data. |
View |
CView |
Manages user interaction with a document. |
Attached to a document. Owned by a frame window. |
Frame window |
CFrameWnd |
Frames a view. |
Owns a view that is attached to a document |
Au programmeur de faire
|
Les MFC s'en occupe
|
---|---|
Derive a document class from class CDocument |
Provide many document services through class CDocument. |
Add data members to your class et
function members |
|
Implement application-specific initialization and cleanup of your document’s data. | Call the appropriate initialization and cleanup functions
at the right times. |
Override CDocument’s Serialize member function
to specify how your data is read and written. |
Provide implementations of File Open, Save, and Save
As that call your Serialize override to read and write your data. |
Objets créés
|
dérivent des MFC
|
---|---|
CSribbleApp |
CWinApp |
CScribbleDoc |
CDocument |
CScribbleView | CView |
CScribbleMainFrame |
CMDIFrameWnd |
CScribbleChildFrame |
CMDIChildWnd |
CAboutDlg |
CDialog |
SetModifiedFlag() |
is a member function of class CDocument. It marks the document as changed
so the framework will prompt the user to save the document when it closes. |
DeleteContents() |
destroy the document’s data
(à overrider) |
UpdateAllViews(View*) |
Cause all views of the data to be updated. argument = pointer to the view that modified the document, NULL si c'est le document lui même. |
Au programmeur de faire
|
Les MFC s'en occupe
|
---|---|
Derive a view class from class CView (ou CScrollView si on veut pouvoir scroller). Other view classes are available as well. | Class CView and its derived classes provide view
services. |
Implement your view’s OnDraw member
function. |
C'est le framework qui appelle la fonction OnDraw
quand il le faut (quand le contexte d'affichage le demande) |
Map Windows messages and commands to member functions of your view. | The framework calls your message-handler member functions
in response to the corresponding Windows messages. |
Action de l'utilisateur
|
Evenement
|
Handler
|
---|---|---|
Presse le bouton gauche |
WM_LBUTTONDOWN |
CScribbleView::OnLButtonDown |
Bouge la souris (whether or not mouse button is pressed) |
WM_MOUSEMOVE |
CScribbleView::OnMouseMove |
Relache le bouton gauche |
WM_LBUTTONUP |
CScribbleView::OnLButtonUp |
une appli qui dessine des point sur une feuille blanche. - le Document stocke en fait la liste des points dessinés - la View représente ces points en les affichant à l'écran On ajoute une fonction Clear-All qui efface tous les point dessinés - le fait d'effacer tous les points, alors la liste des points dans le Document doit êter mise à zéro - on peut se contenter de mettre à zéro la View - mais : la view doit représenter en temps réel les données du Document ! - conclusion : on doit placer ClearAll au niveau du Document |
ClassWizard wrote the following
message-map entry in the document’s message map in ScribbleDoc.cpp: ON_UPDATE_COMMAND_UI( ID_EDIT_CLEAR_ALL, OnUpdateEditClearAll ) The ON_UPDATE_COMMAND_UI macro resembles the ON_COMMAND macro for the OnEditClearAll message handler. In addition, ClassWizard added a new member function declaration for OnUpdateEditClearAll to the CScribbleDoc class definition in ScribbleDoc.h. The function declaration looks like this: afx_msg void OnUpdateEditClearAll( CCmdUI* pCmdUI ); |
Enable( BOOL
) |
the menu item is enabled or disabled (and dimmed or
grayed) |
SetCheck( BOOL ) |
toggle the menu item’s check mark on or off as the line thickness changes. |
Add the Controls
1. From the Controls toolbar, add two edit box controls to the Pen Widths dialog box.
2. From the Controls toolbar, add two static text controls to contain the descriptions for the two edit controls.
For the purposes of Scribble, you won’t have to refer programmatically to the IDs of the text boxes, so you can leave them with their default values (both have the value IDC_STATIC).
3. From the Controls toolbar, add a third button to the two already present.
4. Select the third button to display its property page.
Change its ID to IDC_DEFAULT_PEN_WIDTHS and its caption to Default.
The handler for this button will reset the thick and thin pens to their default widths.
Arrange and Test Controls
Once you’ve added all the controls to the dialog box, you can also:
- Resize the dialog box for a balanced layout .
- Align the controls and make them the same size, using the commands on the Layout menu.
- Define the tab order for the controls.
You can see the tab order by clicking Tab Order from the Layout menu. To change the tab order, click each control in the order you want as the tab order
- Test the dialog box.
If you want to see how the dialog box will look when it’s displayed, click the Test command from the Layou t menu. This displays the dialog box as it will appear in Scribble, enabling you to test aspects such as the tab order, default button, and so on. Exit Test mode by clicking either the OK or Cancel button on the dialog box or by pressing the ESC key.
In the File name box, the name is assigned for the implementation (.cpp) file based on the characters you type.
|
|
In the Minimum Value and Maximum Value boxes, enter 1 and 20, respectively. Click OK. |
CPenWidthsDlg dlg; // Initialize dialog data dlg.m_nThinWidth = m_nThinWidth; dlg.m_nThickWidth = m_nThickWidth; // Invoke the dialog box if (dlg.DoModal() == IDOK) { // retrieve the dialog data m_nThinWidth = dlg.m_nThinWidth; m_nThickWidth = dlg.m_nThickWidth; // Update the pen used by views when drawing new strokes // to reflect the new pen widths for "thick" and "thin". ReplacePen(); } - Scroll to the top of ScribbleDoc.cpp and add the following #include statement: #include "PenWidthsDlg.h" - Save ScribbleDoc.cpp. |