I am trying to implement native Win32 menus in my app.
I am able to display and interact with the menus:
auto hMenu = CreateMenu();
auto hSubMenu = CreatePopupMenu();
#define ID_FILE_EXIT 9001
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
SetMenu(window.getSystemHandle(), hMenu);
and also able to directly receive window messages:
MSG message;
while(PeekMessage(&message, NULL, WM_COMMAND, WM_COMMAND, PM_REMOVE)) {
//do_stuff();
}
but I never receive any WM_COMMAND messages that the menus should be sending out. (if I change both the WM_COMMAND in the PeekMessage call to 0, I get mouse etc events, but asking for only WM_COMMAND gives me nothing)
I am not very experienced with the Win32 api, so I am not sure if I am using the wrong method for WM_COMMAND messages, or if somehow SFML is eating the message before I can see it. I am doing the PeekMessage stuff before my SFML event handler, if that matters.
As a simple test I made a modification to WindowImplWin32.cpp that gets menus working 90% 100%:
in WindowImplWin32::processEvent() at the end of the big switch:
case WM_COMMAND :
if (HIWORD(wParam)!=0) break; // Only handle menu sources
Event event;
event.type = Event::MenuitemSelected;
event.menuAction.identifier = LOWORD(wParam);
pushEvent(event);
break;
Along with creating the obvious structures in event.hpp. Now I can use SFML's event handler to handle menu events. I've only tried handling the menubar though, no dialog boxes and whatever else. That is enough for my current project.
The reason I say 90% and not 100% is that my app now hangs on exit. I'm guessing it's something related to it somehow skipping SFML's handling of quit messages, but I don't understand how. (My window closes and the console stays behind, followed by Windows saying the app has hung)
-edit-
Actually, it turned out to be a problem with the SVN (it hangs on exit even with a virgin copy of the source, compiled with MSVC2010).
I applied my same modifications to the 2.1 release source and it works 100% fine now.