Notice
Recent Posts
Recent Comments
Link
Lumiroot
CDialogBar 본문
How to initialize child controls in a derived CDialogBar
Article ID | : | 185672 |
Last Review | : | November 21, 2006 |
Revision | : | 3.1 |
This article was previously published under Q185672
SUMMARY
When creating a simple CDialogBar, such as one with only CButtons similar to MFC's print preview, it is not necessary to derive from CDialogBar because the parent of CControlBar receives the notification messages from any child controls.
However, in the case of a more complex CDialogBar, which might have a drop- down combo box, a treeview, or ActiveX control, it might be useful to derive from CDialogBar to provide initialization for the child controls.
Because ClassWizard does not support deriving a class from CDialogBar, this article shows the steps necessary to create a class from CDialog and then "convert" the class to CDialogBar.
However, in the case of a more complex CDialogBar, which might have a drop- down combo box, a treeview, or ActiveX control, it might be useful to derive from CDialogBar to provide initialization for the child controls.
Because ClassWizard does not support deriving a class from CDialogBar, this article shows the steps necessary to create a class from CDialog and then "convert" the class to CDialogBar.
MORE INFORMATION
To start out, create a CDialog class with the child controls you want to use. You can transform the CDialog class into a CDialogBar class using the following nine steps:
1. | Change the base class from CDialog to CDialogBar in the class declaration. Don't forget to also change the base class in BEGIN_MESSAGE_MAP in the .cpp file. |
2. | Change the constructor in both the .h and the .cpp files. Also make the change to the DoDataExchange(). Below are three items to change. Change the following from to the following: The key to the transformation is the conversion of the virtual OnInitDialog() member function to the WM_INITDIALOG message mapped method by changing the OnInitDialog method and by adding the ON_MESSAGE() handler. You may not have an override of OnInitDialog(). If not, add one before proceeding. |
3. | Remove "virtual BOOL OnInitDialog();" from the class header and add "afx_msg LONG OnInitDialog ( UINT, LONG );" in its place. For example: Now, in the class implementation section, make the corresponding changes. |
4. | Add "ON_MESSAGE(WM_INITDIALOG, OnInitDialog );" to the message map in the .CPP implementation file. For example: Now, convert the virtual OnInitDialog() to the message-mapped OnInitDialog(). |
5. | Make the OnInitDialog() conversion as follows: to the following: The CDialogBar class doesn't have a virtual OnInitDialog(), and therefore calling one does not work. UpdateData is called to subclass or initialize any child controls. |
6. | Make sure the dialog box resource styles to the following:
Style: Child At this point, everything has been reconnected to make the transformation from a CDialog class to a CDialogBar class work correctly. Now, create and use it.Boarder: None Visible: Unchecked |
7. | Add an instance of the derived CDialogBar to the CframeWnd-derived class (normally called CMainFrame). For example:
|
8. | Call the create method for the m_myDlgBar variable in the CFrameWnd::OnCreate() method similar to the following:
|
9. | Finally, if you want to support dynamic docking and resizing of the CDialogBar, add the following lines to the end of CMainFrame::OnCreate():
|
Comments