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... "));