Graphics Reference
In-Depth Information
MFC CDialog class. Recall that our main application window is a GUI
element, and that we can define control variables for GUI elements. Now,
refer to Listing 2.3: the dlg object instantiated in the InitInstance()
function is the control variable for our main application window, and the
data type for our main application window is CTutorialDlg . Listing 2.3
shows dlg is referenced by m _ pMainWnd , an instance variable of theApp .
When we examine the structure of the TutorialDlg.cpp file (refer to Listing 2.4),
we observe the following.
Object-oriented mechanism. CTutorialDlg subclasses from the MFC
CDialog class; this means that our main application window inherits vast
predefined functionality from CDialog (e.g., mouse events, timer events).
Notice the virtual functions that are overridden (e.g., OnInitDialog() );
these are examples of modifying predefined GUI element behaviors.
SystemInitialization (A). The OnInitDialog() is our opportunity to
perform initialization for the application window, much like the function-
ality of the SystemInitialization() function discussed in Section 1.2.
Because we are overriding a virtual function, it is important to follow the
protocol. In this case, we must invoke the superclass method CDialog::On
InitDialog() , and we must return TRUE upon successful operations.
Redraw / Paint event (B and C). The BEGIN _ MESSAGE _ MAP macro ( B )helps
register events for services. Here we see the registration of ON _ WM _ PAINT ,
the Redraw / Paint event. In this case, CTutorialDlg must override the
OnPaint() function to service the event. Because the application window
is empty, this function does not do anything.
GUI element and control variable data exchange (D). As we will see in
later tutorials, this function helps maintain the consistency of state informa-
tion between the front-end GUI elements and their corresponding control
variables in the back end.
Source file naming convention. Note that of the above file names, Resource
.h , StdAfx.h ,and StdAfx.cpp are governed by MFC. We will name all of the tu-
torials TutorialApp.h/.cpp for the application and TutorialDlg.h/.cpp for
the main application window. For the rest of the tutorials in this chapter, we will
only need to work with the CTutorialDlg class (our main application window).
Search WWH ::




Custom Search