SUPPORTING THE DIALOG CONTROLS

For the pen dialog you’ll store the selected pen width in a data member, m_PenWidth, of the CPenDialog class. You can either add the data member by right-clicking the CPenDialog class name and selecting from the context menu, or you can add it directly to the class definition as follows:

class CPenDialog : public CDialogEx
{
// Construction
public:
   CPenDialog(CWnd* pParent = NULL);   // standard constructor
        
// Dialog Data
   enum { IDD = IDD_PENWIDTH_DLG };
        
   int m_PenWidth;                     // Record the current pen width
        
// Plus the rest of the class definition....
        
};
NOTE If you use the context menu for the class to add m_PenWidth, be sure to add a comment to the member variable definition. This is a good habit to get into, even when the member name looks self-explanatory.

You’ll use the m_PenWidth data member to set the radio button corresponding to the current pen width in the document as checked. You’ll also arrange for the pen width that is selected in the dialog to be stored in this member, so that you can retrieve it when the dialog closes. At this point you can initialize m_PenWidth to 0 in the CPenDialog class constructor:

CPenDialog::CPenDialog(CWnd* pParent /*=NULL*/)
                : CDialogEx(CPenDialog::IDD, pParent), m_PenWidth(0)
{
}

Initializing Dialog Controls

You can initialize the radio buttons by overriding the OnInitDialog() function that is inherited from the CDialog base class. This is called in response to a WM_INITDIALOG message, which is sent during ...

Get Ivor Horton's Beginning Visual C++ 2012 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.