Advertisement
6_2008-2009 Files/ File Controls/ Input/ Output #205989

Making a menu using winapi non-mfc

This code shows how to easily and quickly create a menu on a non-mfc window using winapi. I this code is versatile, and extremely useful as I for one hate resources. This example deals with making a "file --> exit" menu. The methods used in making this apply to all menus.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
//define any menu ITEMS u might have, in this case "exit"
#define CM_MENU_FILE_EXIT 2001
//place this in LRESULT CALLBACK WindowFunc
HMENU hMenu, hSubMenu;
//create the menu in the WM_CREATE section of LRESULT CALLBACK WindowFunc
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, CM_MENU_FILE_EXIT, "E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
SetMenu(hwnd, hMenu);
//note - if creating extra menus dont forget to call hSubmenu = CreatePopupMenu(); again or all your "menu items" will just b added to the old menu
//give the "menu item" an action under WM_COMMAND
switch(LOWORD(wParam)) {
case CM_MENU_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
//i hope this has been helpful, feel free to comment
Původní komentáře (3)
Obnoveno z Wayback Machine