Author Topic: Problems using drop-down menus.  (Read 1130 times)

Lightman

  • Regular Member
  • *
  • Posts: 35
Problems using drop-down menus.
« 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.

Code: [Select]
hMenu   HMENU ?

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

Code: [Select]
invoke GetDlgItem, hWnd, IDM_MENU
mov hMenu, eax

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

Code: [Select]
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

  • Member
  • *****
  • Posts: 7632
  • Assembler is fun ;-)
    • MasmBasic
Re: Problems using drop-down menus.
« Reply #1 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?

dedndave

  • Member
  • *****
  • Posts: 8741
  • Still using Abacus 2.0
    • DednDave
Re: Problems using drop-down menus.
« Reply #2 on: October 30, 2015, 01:15:48 AM »
normally, i use MF_BYCOMMAND, MF_BYPOSITION

Code: [Select]
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

  • Regular Member
  • *
  • Posts: 35
Re: Problems using drop-down menus.
« Reply #3 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
Regards,

Lightman

dedndave

  • Member
  • *****
  • Posts: 8741
  • Still using Abacus 2.0
    • DednDave
Re: Problems using drop-down menus.
« Reply #4 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

dedndave

  • Member
  • *****
  • Posts: 8741
  • Still using Abacus 2.0
    • DednDave
Re: Problems using drop-down menus.
« Reply #5 on: October 30, 2015, 02:11:07 AM »
if it is to be a context menu, use LoadMenu and TrackPopupMenu

dedndave

  • Member
  • *****
  • Posts: 8741
  • Still using Abacus 2.0
    • DednDave
Re: Problems using drop-down menus.
« Reply #6 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

dedndave

  • Member
  • *****
  • Posts: 8741
  • Still using Abacus 2.0
    • DednDave
Re: Problems using drop-down menus.
« Reply #7 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

Lightman

  • Regular Member
  • *
  • Posts: 35
Re: Problems using drop-down menus.
« Reply #8 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
Regards,

Lightman

Lightman

  • Regular Member
  • *
  • Posts: 35
Re: Problems using drop-down menus.
« Reply #9 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
Regards,

Lightman

jj2007

  • Member
  • *****
  • Posts: 7632
  • Assembler is fun ;-)
    • MasmBasic
Re: Problems using drop-down menus.
« Reply #10 on: October 30, 2015, 07:34:48 AM »
      ; Load the handles for my widgets...
      ; invoke   GetDlgItem, hWnd, IDM_MENU
      invoke GetMenu, hWnd