Adding Dialog Controls at Run Time
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 run time, 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.
Add an ID constant for the new control. Right-click on the dialog class in Resource View and choose Resource Symbols to open the Resource Symbols dialog box. Add the new constant.
Use Class View's Property Page to override CDialog::OnInitDialog. This function should call the embedded control window's Create member function. This call displays the new control in the dialog box. Windows will destroy the control window when it destroys the dialog box.
In your derived dialog class, manually add the necessary notification message handlers for your new control.
In Chapter 12 you'll add a rich edit control to a view at run time.