-
Menu not appearing
I am trying to get a menu working & am following how I did it last time (which worked in the same compiler) copying it exactly, the menu doesn't appear. I am using Dev-C++
Here is the function to create the menu:
Code:
HMENU CreateMainMenu(HWND hwnd) {
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, WM_CLOSE, "E&xit\tAlt+F4");
AppendMenu(hSubMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "&File");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING | MF_UNCHECKED, 1002, "Show Postfix notation");
AppendMenu(hSubMenu, MF_STRING |MF_POPUP, (UINT)hSubMenu, "Functions");
SetMenu(hwnd, hMenu);
return hMenu;
}
& have called it just before the call to ShowWindow in WinMain().
-
-
Nope, DrawMenuBar did nothing. After debugging, SetMenu & DrawMenuBar both succeed & return a non-zero value.
-
Looking at the code rather than the explanation, the second and fourth AppendMenu calls are appending to the wrong menu. The first parameter should be hMenu not hSubMenu. As it is currently, hMenu is empty when set to the hwnd.
Depending on how old your copy of the SDK is, the casts on the third parameter are to the wrong type. It should be a cast to UINT_PTR if you want it to be reliable on 64-bit systems.
-
Thanks, supprised I didn't notice that. Changed cast as well. Works fine now.