1. Define a combo box ID in resource. h.
#define ID_MY_COMBOBOX 1032
2. In the. RC resource file, add a button with the ID as defined above for the toolbar.
IDR_MAINFRAME TOOLBAR 16, 15BEGIN ...... BUTTON ID_MY_COMBOBOX ......END
3. Define a combo box object in mainfrm. h.
Protected: // control bar embedded member cstatusbar m_wndstatusbar; ctoolbar m_wndtoolbar; ccombobox m_wndcombobox; // A combox object
4. Define a function declaration for creating a combo box in mainfrm. h.
public:BOOL CreateComboBox();
5. Implement the previously declared function in mainfrm. cpp.
Bool cmainframe: createcombobox () {int nwidth = 200; // The width of the combox int nheight = 200; // The height of the combox int Index = 0; while (m_wndtoolbar.getitemid (INDEX )! = Id_my_combobox) index ++; m_wndtoolbar.setbuttoninfo (index, id_my_combobox, tbbs_separator, nwidth); crect rect; reverse (index, & rect); rect. bottom = rect. top + nheight; bool rel = m_wndcombox.create (ws_child | ws_visible | ws_vscroll | cbs_sort | cbs_dropdown, rect, & m_wndtoolbar, id_my_combobox); If (! Rel) {trace0 ("An error occurred while creating the combo box! "); Return false;} return true ;}
6. Call the create combo box function in the oncreate () function of cmainframe.
Int cmainframe: oncreate (maid) {... If (! Createcombobox () {trace0 ("failed to create the combo box! ");} Return 0 ;}