Windows Programming menu

Source: Internet
Author: User

If there is nothing to write, merge the two into one. The first part of the code is in menudemo, and the second part is popmenu.

Switch (Message) {Case wm_command: // obtain the menu handle hmenu = getmenu (hwnd); // loword (wparam) is the menu idswitch (loword (wparam) {Case idm_file_new: case idm_file_open: Case idm_file_save: case when: messagebeep (0); break; Case idm_app_exit: sendmessage (hwnd, wm_close, 0,0); Return 0; case when: Case idm_edit_cut: Case idm_edit_copy: case idm_edit_paste: Case idm_edit_clear: messagebeep (0); Return 0; Case idm_bkgnd_white: Case idm_bkgnd_ltgray: Case idm_bkgnd_gray: Case idm_bkgnd_black: // set checkmenuitem (hmenu, iselection, mf_unchecked) to cancel the selected state; // obtain the menu idiselection = loword (wparam); // set it to checkmenuitem (hmenu, wparam, mf_checked); // setclasslong (hwnd, gcl_hbrbackground, (long) getstockobject (idcolor [loword (wparam)-idm_bkgnd_white]); // refresh invalidaterect (hwnd, null, true); Return 0; Case idm_timer_start: If (settimer (hwnd, id_timer, 1000, null) {// set the State enablemenuitem (hmenu, idm_timer_start, mf_grayed) of the subitem of the menu ID ); enablemenuitem (hmenu, idm_timer_stop, mf_enabled);} return 0;

Point. X = loword (lparam); point. y = hiword (lparam); // convert the window coordinate to the screen coordinate clienttoscreen (hwnd, & Point); // specify the position to display the menu, and the coordinates are the screen coordinate trackpopupmenu (hmenu, tpm_rightbutton, point. x, point. y, 0, hwnd, null );


The second code is just two functions.

Add more content:

Getsystemmenu

Function: This function allows applications to access window menus (system menus or control menus) for copying or modifying ).

Function prototype: hmenu getsystemmenu (hwnd, bool brevert );

Parameter: hwnd: handle that owns the copy of the window menu.

Brevert: Specifies the operation to be executed. If this parameter is set to false, getsystemmenu returns the copy handle of the current window menu.

This copy is initially the same as the window menu, but can be modified.

If this parameter is set to true, getsystemmenu resets the window menu to the default state. If a previous Window Menu exists, it will be destroyed.

Hmenu = getsystemmenu (hwnd, false); // draw a horizontal differentiation line appendmenu (hmenu, mf_separator, 0, null); // dynamically Add the subitem appendmenu (hmenu, mf_string, idm_sys_about, text ("about... "));

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.