The MASM Forum

General => The Campus => Topic started by: Lightman on October 29, 2015, 09:44:38 PM

Title: Problems using drop-down menus.
Post by: Lightman on October 29, 2015, 09:44:38 PM
Hi Everyone,

I'm having some problems using drop-down menus. I can create the menu and then select options from it, but I can edit the menu options. I'm trying to disable/enable or grey/ungrey menu options.

I figure that I need to use the EnableMenuItem function, but first I need to get and store the handle for the menu. I'm using RadASM, so I add the handle into my .data ? section.


hMenu   HMENU ?


Then, in my code section, grab the handle of the menu...


invoke GetDlgItem, hWnd, IDM_MENU
mov hMenu, eax


Now, I'm all set... I can call EnableMenuItem...


invoke EnableMenuItem, hMenu, IDM_OPEN, MF_ENABLED


..and I'm done. But sadly not.... The code compiles and runs but appear to have no effect on the menu. Can anyone see where I am going wrong?

Regards,

Lightman


Title: Re: Problems using drop-down menus.
Post by: jj2007 on October 30, 2015, 12:51:49 AM
Hi Lightman,

Welcome to the forum :icon14:

Without seeing your full code, it is difficult to help you. Of course, if I had unlimited time and nothing else to do, I could take your snippets, add headers and WndProc and all that and try to find out. But why should I? Wouldn't it be much easier if you posted your code?
Title: Re: Problems using drop-down menus.
Post by: dedndave on October 30, 2015, 01:15:48 AM
normally, i use MF_BYCOMMAND, MF_BYPOSITION

INVOKE  EnableMenuItem,hMenu,IDM_ITEM,MF_ENABLED or MF_BYCOMMAND

as it happens, both MF_BYCOMMAND and MF_ENABLED are 0 (defaults)
so, it doesn't really need to be in there, it's just clearer

if it isn't working, i suggest you don't have a valid handle for the parent menu
i don't think GetDlgItem is the right function for this

usually, if i need a menu handle later on, i store the handle for it when it is created or loaded
as far as i know, you can only get the main window menu, not a drop-down (GetMenu, GetSubMenu)
by drop-down, i am guessing you are refering to a context menu ?
Title: Re: Problems using drop-down menus.
Post by: Lightman on October 30, 2015, 01:52:50 AM
Hi Everyone,

An example of this issue in action...

I'm using RadASM, if that makes a difference...

This is just a rough 'n' ready example, it does not really do anything accept enable/disable menus... or not in this case...

Regards,

Lightman
Title: Re: Problems using drop-down menus.
Post by: dedndave on October 30, 2015, 02:09:50 AM
ok, when creating a dialog, there is no need to register a window class
the system has pre-defined classes for dialog boxes

so - that class isn't used

in init dialog, you want to use LoadMenu and AttachMenu, i think (can't say as i have ever used a main menu with a dialog box - lol)
when you LoadMenu, save the handle at that time
Title: Re: Problems using drop-down menus.
Post by: dedndave on October 30, 2015, 02:11:07 AM
if it is to be a context menu, use LoadMenu and TrackPopupMenu
Title: Re: Problems using drop-down menus.
Post by: dedndave on October 30, 2015, 02:12:47 AM
also - a dialog box does not require a message loop
again, the system takes care of that for you

the window class and message loop are used if you create a window with CreateWindowEx
Title: Re: Problems using drop-down menus.
Post by: dedndave on October 30, 2015, 02:26:36 AM
i don't have masm32 installed on this machine, so i can't point to a specific folder
but, you can find dialog examples in \masm32\examples
Title: Re: Problems using drop-down menus.
Post by: Lightman on October 30, 2015, 02:44:31 AM
Thanks for that dedndave,

You are quite right, SendDlgItemMessge is not the right function. Iczelion's tutorial 16 on Event Objects shows how this can be done using GetMenu. Right after the main window is created, GetMenu is called to return the menu handle. This was the missing element. With this safely saved away I'm free to tinker with the menu later.

The  Main Window vs. Dialog window thing has caused me confusion in the past. I'm following Iczelion's tutorial and coding the examples up in RadASM. Being a RAD package, RadASM gives me a template to build my code from. This creates a dialog as a main window and attaches a menu to it. I can then add more menu options, buttons and the like. Coming from a Visual Studio background, this kinda makes sense. I'm up to Tutorial 17 and starting to want to play around with my own ideas...

I've attached a copy of the code with the menu thing 'fixed'....

Regards,

Lightman
Title: Re: Problems using drop-down menus.
Post by: Lightman on October 30, 2015, 02:51:16 AM
Hi,

Ah... Cool... 

My \masm32\ directory does come with examples... I though it was just the compiler....

Regards,

Lightman
Title: Re: Problems using drop-down menus.
Post by: jj2007 on October 30, 2015, 07:34:48 AM
      ; Load the handles for my widgets...
      ; invoke   GetDlgItem, hWnd, IDM_MENU
      invoke GetMenu, hWnd