Adding a Menu to a WTL CWindow (non modal)
- Go to resource view and create the menu in your project using the menu editor
- Load the menu like this:
CMenu menu;
menu.Attach( LoadMenu( _Module.GetResourceInstance(),MAKEINTRESOURCE(IDR_MENU1)));
- Include the menu in the windows OnCreate method
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
SetMenu( menu );
}
- Add handlers to the Message map:
BEGIN_MSG_MAP(CATLWindow)
MESSAGE_HANDLER( WM_CLOSE, OnClose)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
// to link a method per item:
COMMAND_ID_HANDLER( ID_MENU_ITEM_1, OnMenuItem1)
COMMAND_ID_HANDLER( ID_MENU_ITEM_2, OnMenuItem1)
// to make a handler for all messages at once:
// MESSAGE_HANDLER( WM_COMMAND, OnMenu)
END_MSG_MAP()
- The COMMAND_ID_HANDLER method skeleton:
LRESULT OnMenuItem1( WORD code, WORD id, HWND hwnd, BOOL& bHandled)
{
return 0;
}
- The MESSAGE_HANDLER method skeleton:
LRESULT OnMenu( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
PostQuitMessage(0);
return 0;
}
- That's it