Adding Dialog Controls at Runtime
You've seen how to use the resource editor to create dialog controls at build time. If you need to add a dialog control at runtime, here are the programming steps:
- Add an embedded control window data member to your dialog class. The MFC control window classes include CButton, CEdit, CListBox, and CComboBox. An embedded control C++ object is constructed and destroyed along with the dialog object.
- Choose Resource Symbols from Visual C++'s View menu. Add an ID constant for the new control.
- Use ClassWizard to map the WM_INITDIALOG message, thus overriding CDialog::OnInitDialog. This function should call the embedded control window's Create member function. This call displays the new control in the dialog. Windows will destroy the control window when it destroys the dialog window.
- In your derived dialog class, manually add the necessary notification message handlers for your new control.
In Chapter 13, you'll be adding a rich edit control to a view at runtime.