News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Problems using drop-down menus.

Started by Lightman, October 29, 2015, 09:44:38 PM

Previous topic - Next topic

Lightman

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


Regards,

Lightman

jj2007

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?

dedndave

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 ?

Lightman

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
Regards,

Lightman

dedndave

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

dedndave

if it is to be a context menu, use LoadMenu and TrackPopupMenu

dedndave

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

dedndave

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

Lightman

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
Regards,

Lightman

Lightman

Hi,

Ah... Cool... 

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

Regards,

Lightman
Regards,

Lightman

jj2007

      ; Load the handles for my widgets...
      ; invoke   GetDlgItem, hWnd, IDM_MENU
      invoke GetMenu, hWnd