Dialogs normally contain one or more control windows such as buttons, list boxes, and edit controls. The type and position of those controls is typically specified in a dialog template resource. If you create a derived control class as described in the previous sections, you cannot specify the derived control in a dialog template since the resource compiler does not know anything about your derived class.
·To place a derived control in a dialog:
1.Embed an object of the derived control class in the declaration of your derived dialog class, as shown in the following class declaration.
class CMyDialog : public CDialog {protected: CNumEdit m_numEdit;
public: virtual BOOL OnInitDialog(); };
2.Override the OnInitDialog message-handler function in your dialog class to call Create for the derived control that you embedded in your dialog box. A sample OnInitDialog is shown here:
BOOL CMyDialog::OnInitDialog()
{
// create the derived control
RECT r;
r.top = 50;
r.bottom = 75;
r.left = 20;
r.right = 120;
m_numEdit.Create( WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER,
r,
this,
ID_MYNUMEDIT );
// other initialization tasks...
return TRUE;
}
Because the derived controls are embedded in the dialog, they will be automatically destroyed when the dialog is destroyed.