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:

  1. 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.

  2. Choose Resource Symbols from Visual C++'s View menu. Add an ID constant for the new control.

  3. 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.

  4. 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.



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net