To summarize the usage of win32 menu:

Source: Internet
Author: User

[Cpp] // first define the menu ID # define IDM_FILE_NEW 40001 # define IDM_FILE_OPEN 40002 # define IDM_EDIT_COPY 40003 # define IDM_EDIT_CUT 40004 HMENU hMenu; HMENU hMenuPop; // Menu Append hMenu = CreateMenu (); // Main Menu, horizontal hMenuPop = CreateMenu (); // drop-down Menu, vertical AppendMenu (hMenuPop, MF_STRING, IDM_FILE_NEW, TEXT ("New"); AppendMenu (hMenuPop, MF_STRING, IDM_FILE_OPEN, TEXT ("Open"); AppendMenu (hMenu, MF_POPUP, (unsigned int) hMe NuPop, TEXT ("File"); hMenuPop = CreateMenu (); AppendMenu (hMenuPop, MF_STRING, IDM_EDIT_COPY, TEXT ("Copy"); AppendMenu (hMenuPop, MF_SEPARATOR, 0, NULL); AppendMenu (hMenuPop, MF_STRING, IDM_EDIT_CUT, TEXT ("Cut"); AppendMenu (hMenu, MF_POPUP, (unsigned int) hMenuPop, TEXT ("Edit ")); // Menu Insert InsertMenu (hMenu, 0, uTemp, IDM_EDIT_CUT + 7, TEXT ("NewAdd"); SetMenu (hwnd, hMenu); others are okay to say, explain InsertMenu (because it can be found online) The InsertMenu part is CMenu). The first parameter of InsertMenu is the menu HMENU to be inserted, and the second parameter is the position of the menu item to be input, for example, "0" indicates that the value is inserted before the menu "New" (that is, the first item), and "1" indicates that the value is inserted after the value of "New" (the second item). The third parameter indicates the flag, generally, you only need to specify UINT uTemp = MF_BYPOSITION | MF_POPUP. The fourth parameter indicates the ID of the new menu item, which is IDM_EDIT_CUT + 7; the fifth parameter refers to the name of the menu item to be added. Whether AppendMenu is good or InsertMenu is good, SetMenu must be set to the original hwnd after the operation, to make the menu items after the operation take effect .. Why is there a menu ID .. Let's think about this problem-when we want to process menu item events, what can we use to locate the menu items we want to process?... Therefore, the menu item ID is very important, because we need to use this ID in WM_COMMAND to locate a menu item: [cpp] lresult callback WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {switch (message) {case WM_COMMAND: switch (wParam) {case IDM_FILE_NEW: MessageBox (hwnd, TEXT ("this menu is IDM_FILE_NEW"), szAppName, MB_ OK); break; case IDM_FILE_OPEN: MessageBox (hwnd, TEXT ("this menu is IDM_FILE_OPEN"), szAppName, MB_ OK); break; default: break;} break; case WM_DESTROY: postQuitMessage (0); return 0;} return DefWindowProc (hwnd, message, wParam, lParam);} The summary is as follows:

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.