4
votes

I've created a simple Dialog box with a few controls (edit, text, etc) and saved it to the resource folder in GME/GME.rc/Dialog

I added an auto-gen'd event handler which created a new class (Class.cpp for the purposes of this example) Note: the Class::Class(CWnd *pParent) : CDialogEx(Class::IDD, pParent) constructor is empty, I'm not sure if that's relevant but I don't think it is..

There's a MESSAGE_MAP COMMAND(menu_item_id, &class::member_function()) invocation within the Class.cpp was auto-generated. It's wrapped in the standard BEGIN_MESSAGE_MAP macro stuff.

However: when the menu item is clicked, the item remains gray. The properties for "enabled=true" and "gray=false" are both properly configured. So, I assume this is error is due to the message handler isnt registered.

Any help would be appreciated.

3
How are you displaying the menu?Mark Ransom
From the IDR_MAINFRAME menu, I add a menu, right clicked an "add event handler" and selected the CUserInformation class to handle the COMMAND messagetype. pastie.org/3891015 <-- header file ; pastie.org/3891019 <-- implementation fileAndrew
I still don't see any code to produce a menu, and I'm not aware of any way to add one to a dialog.Mark Ransom
The menu is generated automatically by the frame which pops up once the GME.rc dialog is double clicked.Andrew

3 Answers

1
votes

Without code, it's pretty darn hard to help. Are you sure you put the message handler for the menu id in either a CView, CFrame, CDocument, or CWinApp derived class? If you put the menu handler in your dialog class, it's not going to do you much good.

1
votes

Dialogs do not contain the code to run through the list of ON_UPDATE_COMMAND_UI handlers that MFC uses to enable menu items. Ordinarily this is handled by CFrameWnd for example. Try calling UpdateDialogControls in your OnInitDialog function.

I see that your code is also missing the ON_UPDATE_COMMAND_UI macro for the menu item, even though the handler it would reference was created for you.

0
votes

You add menu item handlers to the window that has the menu, which is usually the CMainFrame. Copy the message map and handler to the CMainFrame and see if that helps. I'm not sure what you're trying to do here - I assume you want to display 'Class' (maybe better to edit your post to call this 'ExampleDialog' or something...) when the menu item is clicked, right? Or did you somehow add a menu to your CDialogEx-derived class? If the last, I guess this is what Mark is referring to - 'how are you displaying the menu'? How are you manually adding a menu to your dialog?