Background
Unlike. NET Compact framework, the native C ++ development dialog box is used.ProgramThere is no menu by default, and you need to add it manually. This article describes how to add a menu to a dialog box program.
. NET Compact framework
By default, a menu item (mainmenu1) is added to the program using. NET Compact framework. You only need to edit the menu display and add and process events to control the menu, which is very convenient.
Native C ++
Using native C ++ for development is quite different. The new dialog box does not have a menu by default. You need to manually add menu support. The following uses a wtl Dialog Box program as an example to describe how to add menu support. The procedure is as follows:
1. Add a menu in the resource file.
2. Edit the menu as needed.
3. Generate a menu in the dialog box.
Modify the oninitdialog () function to generate a menu.
Lresult cconfigdialog: oninitdialog (uint umsg, wparam, lparam, bool & bhandled)
{
// Atlcreateemptymenubar (m_hwnd );
Shmenubarinfo MBI;
Zeromemory (& MBI,Sizeof(Shmenubarinfo ));
MBI. cbsize =Sizeof(Shmenubarinfo );
MBI. hwndparent = m_hwnd;
MBI. ntoolbarid = idr_menu_config;// Menu resource ID
MBI. hinstres = modulehelper: getresourceinstance ();// Getmoduleinstance (); // similar as: AfxGetInstanceHandle (); In MFC
MBI. dwflags | = shcmbf_hmenu;
If(! Shcreatemenubar (& MBI ))
{
MessageBox (_ T ("Fail to create menu ."));
}
ReturnBhandled = false;
}
4. Add menu to process events
Add event processing ing to the cconfigdialog class. Id_ OK and id_cancel are respectively the IDs of menu items.
Begin_msg_map (cconfigdialog)
Command_id_handler (id_ OK, onok)
Command_id_handler (id_cancel, oncancel)
End_msg_map ()
Lresult onok (Word/* Wnotifycode */, Word/* WID */, Hwnd/* Hwndctl */, Bool &/* Bhandled */);
Lresult oncancel (Word/* Wnotifycode */, Word/* WID */, Hwnd/* Hwndctl */, Bool &/* Bhandled */);
Add processing functions to CPP.
Lresult cconfigdialog: onok (word wnotifycode, word WID, hwnd hwndctl, bool & bhandled)
{
MessageBox (_ T ("OK"));
Return0;
}
Lresult cconfigdialog: oncancel (word wyycode, word WID, hwnd hwndctl, bool & bhandled)
{
MessageBox (_ T ("Cancel"));
Return0;
}
Finished, such.
Click OK.