What do we have in this Module?
This section documents the structures, styles, and callback functions used by the Microsoft Foundation Class Library and the MFC message maps.
Structures Used by MFC
The following table lists structures that are called from various member functions.
|
Styles Used by MFC
Use the following styles when you create the corresponding MFC object. In most cases, these styles are set in the dwStyle parameter of the class Create() function.
MFC Styles
Style |
Description |
Button styles |
Applies to CButton Class objects, such as radio buttons, check boxes and pushbuttons. Specify a combination of styles in the dwStyle parameter of CButton::Create. |
Combo-box styles |
Applies to CComboBox Class objects. Specify a combination of styles in the dwStyle parameter of CComboBox::Create. |
Edit styles |
Applies to CEdit Class objects. Specify a combination of styles in the dwStyle parameter of CEdit::Create. |
Frame-window styles |
Applies to CFrameWnd Class objects. Specify a combination of styles in the dwStyle parameter of CFrameWnd::Create. |
List-box styles |
Applies to CListBox Class objects. Specify a combination of styles in the dwStyle parameter of CListBox::Create. |
Message-box styles |
Applies to AfxMessageBox items. Specify a combination of styles in the nType parameter of AfxMessageBox. |
Scroll-bar styles |
Applies to CScrollBar Class objects. Specify a combination of styles in the dwStyle parameter of CScrollBar::Create. |
Static styles |
Applies to CStatic Class objects. Specify a combination of styles in the dwStyle parameter of CStatic::Create. |
Window styles |
Applies to CWnd Class objects. Specify a combination of styles in the dwStyle parameter of CWnd::Create or CWnd::CreateEx. |
Extended window styles |
Applies to CWnd Class objects. Specify a combination of styles in the dwExStyle parameter of CWnd::CreateEx. |
Table 2. |
Callback Functions Used by MFC
Three callback functions appear in the Microsoft Foundation Class Library. A description of callback functions that are passed to CDC::EnumObjects, CDC::GrayString, and CDC::SetAbortProc follows this topic. Note that all callback functions must trap MFC exceptions before returning to Windows, since exceptions cannot be thrown across callback boundaries.
Message Maps
This section of the reference lists all message mapping macros and all CWnd message-map entries along with the corresponding member function prototypes:
Category |
Description |
WM_COMMAND Message Handler |
Handles WM_COMMAND messages generated by user menu selections or menu access keys. |
Child Window Notification Message Handlers |
Handle notification messages from child windows. |
WM_ Message Handlers |
Handle WM_ messages, such as WM_PAINT. |
User-Defined Message Handlers |
Handle user-defined messages. |
Table 3. |
Since Windows is a message-oriented operating system, a large portion of programming for the Windows environment involves message handling. Each time an event such as a keystroke or mouse click occurs, a message is sent to the application, which must then handle the event. The Microsoft Foundation Class Library offers a programming model optimized for message-based programming. In this model, "message maps" are used to designate which functions will handle various messages for a particular class. Message maps contain one or more macros that specify which messages will be handled by which functions. For example, a message map containing an ON_COMMAND macro might look something like this:
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
ON_COMMAND(ID_MYCMD, OnMyCommand)
// ... More entries to handle additional commands
END_MESSAGE_MAP( )
The ON_COMMAND macro is used to handle command messages generated by menus, buttons, and accelerator keys. Macros are available to map the following:
Windows Messages
Control notifications.
User-defined messages.
Command Messages
Registered user-defined messages.
User-interface update messages.
Ranges of Messages
Commands.
Update handler messages.
Control notifications.
Although message-map macros are important, you generally won't have to use them directly. This is because the Properties window automatically creates message-map entries in your source files when you use it to associate message-handling functions with messages. Any time you want to edit or add a message-map entry, you can use the Properties window. The Properties window does not support message-map ranges. You must write these message-map entries yourself. However, message maps are an important part of the Microsoft Foundation Class Library. You should understand what they do, and documentation is provided for them.
Message Map Macros
To support message maps, MFC supplies the following macros:
Message-Map Declaration and Demarcation Macros
DECLARE_MESSAGE_MAP |
Declares that a message map will be used in a class to map messages to functions (must be used in the class declaration). |
BEGIN_MESSAGE_MAP |
Begins the definition of a message map (must be used in the class implementation). |
END_MESSAGE_MAP |
Ends the definition of a message map (must be used in the class implementation). |
Table 4. |
Message-Mapping Macros
ON_COMMAND |
Indicates which function will handle a specified command message. |
ON_CONTROL |
Indicates which function will handle a specified control-notification message. |
ON_MESSAGE |
Indicates which function will handle a user-defined message. |
ON_OLECMD |
Indicates which function will handle a menu command from a DocObject or its container. |
ON_REGISTERED_MESSAGE |
Indicates which function will handle a registered user-defined message. |
ON_REGISTERED_THREAD_MESSAGE |
Indicates which function will handle a registered user-defined message when you have a CWinThread class. |
ON_THREAD_MESSAGE |
Indicates which function will handle a user-defined message when you have a CWinThread class. |
ON_UPDATE_COMMAND_UI |
Indicates which function will handle a specified user-interface update command message. |
Table 5. |
Message-Map Range Macros
ON_COMMAND_RANGE |
Indicates which function will handle the range of command IDs specified in the first two parameters to the macro. |
ON_UPDATE_COMMAND_UI_RANGE |
Indicates which update handler will handle the range of command IDs specified in the first two parameters to the macro. |
ON_CONTROL_RANGE |
Indicates which function will handle notifications from the range of control IDs specified in the second and third parameters to the macro. The first parameter is a control-notification message, such as BN_CLICKED. |
Table 6. |