Adding a Win32 menu bar to pre-existing GUI

677 Views Asked by At

Menus are pretty popular in many applications:

Example

I've read a lot of threads and have learned out how to add a menu bar to your gui:

//Pseudocode

//..RegisterClassEx

HMENU Menu = CreateMenu();
HMENU Tools = CreateMenu();

AppendMenu(Menu, MF_POPUP, (UINT_PTR)Tools, L"Tools");
AppendMenu(Tools, MF_STRING, 1, L"Test");
SetMenu(hwnd_to_gui, Menu);

//...
//..GetMessage
//..TranslateMessage
//..DispatchMessage

First you RegisterClassEx on your WNDCLASSEX struct that has a property called "lpfnWndProc" which directs to the function to be called when DispatchMessage is called. Then you actually create the menu bar. Finally, you set up a loop that calls GetMessage, and if a message is received, it will translate and dispatch it, effectively calling the lpfnWndProc function.

I was wondering if you could do this with an already existing gui. For example, the console application. I know I can easily set up the menu bar, but handling the input seems to be hard for me.

Console Application w/ Menu Bar Added

I have a loop that calls GetMessage, however it seems to be picking up no input. More information:

  • I am overwriting the current WNDCLASSEX (RegisterClassEx) with a copy of the old one (achieved from GetClassInfoEx) with the only modification that is the "lpfnWndProc" function (to handle input differently).
  • The rewrite seems to be successful, I am just not picking up any input from the GetMessage function (I am clicking buttons, etc.)

Any help on how I would go about doing this?

0

There are 0 best solutions below