In Windows Mobile, native C ++ (wtl, MFC, Win32) is used for development. How can I add a menu for the dialog box?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.