In the following procedure you’ll use WizardBar to add a function handler for the OnPenWidths
message and bind the function to its handler code, which is executed whenever the user clicks the Pen Widths command.
To declare the CPenWidthsDlg object
The New Windows Message Handler dialog box appears.
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();
}
#include "PenWidthsDlg.h"
When you modify ScribbleDoc.cpp, you must include PenWidthsDlg.h so the message handler has access to the dialog class you’ve created.
The OnPenWidths
function:
CPenWidthsDlg
object and sets the values of the m_nThickWidth
and m_nThinWidth
member variables to the current widths of the thick and thin pens. ReplacePen
member function to make the document’s pen use the current widths.
When does the application perform the data exchange and validation defined in the DoDataExchange
function? Recall that DoDataExchange
is called by the UpdateData member function. Just before the dialog box is first displayed on the screen, the framework calls the UpdateData function with an argument of FALSE, which sets the contents of the edit boxes to the values of the member variables. If the user exits the dialog box by clicking the OK button, the framework calls UpdateData with an argument of TRUE, which retrieves the contents of the edit boxes and sets the values of the member variables accordingly. (If the user exits by clicking the Cancel button, the framework doesn’t call UpdateData.)
You don’t have to handle the UPDATE_COMMAND_UI message for the Pen Widths menu item because the menu item doesn’t need to be updated. The command is never disabled since it’s always legal to change the widths of the pens, and there’s no need to add or remove a check mark because the command isn’t a toggle.