Drop Menus and Dialog Boxes

Hi, my application is just a simple dialog box (from a resource script) that I spawn using CreateDialog.

I wanted to add some drop down menus to my application, so I added the following to my resource script just to test everything:

#define IDR_MAIN_MENU 1001
#define MENU_EXIT 1002

//...

IDR_MAIN_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", MENU_EXIT
END
END

The menu displays correctly and all of the menu-items work as expected, however, when I try to use the shortcut method of invoking a top-level menu item, the only thing that happens is "F" in "File" becomes underlined, but the menu itself is never invoked. That is, when I press Alt + F (in this instance, "File" should drop down and show me "Exit" and any other sub-items) nothing seems to happen.

I was wondering if there are any dialog styles that I must pick, or handle a certain windows message in order to "enable" this functionality?

Please let me know if you need any more information.

Thanks in advance,
Plasmator.

P.S.
I even tried manually creating a menu tree using Create[Popup]Menu/AppendMenu/SetMenu in WM_INITDIALOG with the same results; the menus are displayed and work correctly, however, they too are unresponsive to user-generated Alt + CHAR events.

P.P.S.
While we're on this topic, I'd like to add a menu item that would have a check mark (depending if the item is toggled or not) beside it. I've seen quite a few applications that do this... how can I do the same thing?
[1615 byte] By [Plasmator] at [2007-11-20 11:57:36]
# 1 Re: Drop Menus and Dialog Boxes
You can check an uncheck a menu item with CheckMenuItem, e.g.:CheckMenuItem(GetMenu(GetActiveWindow()), MENU_EXIT, MF_CHECKED);
CheckMenuItem(GetMenu(GetActiveWindow()), MENU_EXIT, MF_UNCHECKED);
About the Alt+F shortcut, maybe there are two different menu items with the same shortcut, or maybe it is a problem with TranslateMessage. At http://msdn2.microsoft.com/en-us/library/ms644955.aspx it is noted thatIf applications process virtual-key messages for some other purpose, they should not call TranslateMessage. For instance, an application should not call TranslateMessage if the TranslateAccelerator function returns a nonzero value. Note that the application is responsible for retrieving and dispatching input messages to the dialog box. Most applications use the main message loop for this. However, to permit the user to move to and to select controls by using the keyboard, the application must call IsDialogMessage. For more information, see Dialog Box Keyboard Interface.
olivthill at 2007-11-11 4:02:06 >
# 2 Re: Drop Menus and Dialog Boxes
Thanks for your reply. I looked around and if I remove the call to "IsDialogMessage" the shortcut becomes responsive.
This is my (taken from MSDN) message loop:

MSG msg;
BOOL bRet;

while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

I find that the shortcut works if I change the loop (remove the call to IsDialogMessage) to this:

while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
// Handle the error and possibly exit
}
else if (!IsWindow(hwnd))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

I'm using a modeless dialog and I don't know if this is the correct way to set up my message loop.

Can someone please clarify? ^_^

Thanks.
Plasmator at 2007-11-11 4:03:06 >
# 3 Re: Drop Menus and Dialog Boxes
I was wondering if there are any dialog styles that I must pick, or handle a certain windows message in order to "enable" this functionality?This functionality does not depend on a style. It cannot be enabled or disabled under normal condition. It is a bug.

I am not quite sure what kind of an app it is. From code snippets I gather it is Win32 app (not MFC).

Something is going on and prevent menu from popping. Without seeing your code is very hard to determine what.
However from a behavior you describe I can guess only: check if you have the same combination (&F) used as "hot key" for a button in the dialog?

If you remove IsDialogMessage check, a dialog will be crippled. You will not be able to tab, controls may misbehave.
It may fix conflicting hot keys assignment but will introduce other problems.

I use a term "hot key" instead "acceleration key" to avoid confusion with accelerators.
JohnCz at 2007-11-11 4:03:59 >
# 4 Re: Drop Menus and Dialog Boxes
Thanks for your reply.

You know what's funny?
When I add any control (a button, for example) everything works like it should. The menu is unresponsive to Alt + CHAR commands ONLY when the dialog is empty, i.e., "BEGIN /*nothing*/ END" in the resource script.

Rather strange, don't you think?
Plasmator at 2007-11-11 4:05:04 >
# 5 Re: Drop Menus and Dialog Boxes
Well it is strange and kind of hard to believe that is possible just for the reason you stated.
I still do not know what kind of project it is. Could you post it here?
JohnCz at 2007-11-11 4:06:04 >