News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

checking menu items

Started by timertik, April 21, 2007, 09:19:47 AM

Previous topic - Next topic

timertik

I have a menu in .rc named IDM_MNU
and it has a item in it that i need to check and uncheck and i cant get it to work  ::)
I try
CheckMenuItem

like this:
invoke CheckMenuItem,IDM_MNU,9014,MF_CHECKED

where 9014 is the item

what am i doing wrong?

oh and the item works fine just this will not check nor uncheck

zooba

Replace IDM_MNU with hMenu or whatever you put the return value of LoadMenu into. As long as your menu has a unique ID you'll be fine.

Cheers,

Zooba :U

timertik

thanks this sheds some new light on the subject .
but I still cant get it right

invoke LoadMenu,hMenu,IDM_MNU
invoke CheckMenuItem,hMenu,9014,MF_CHECKED


this should work right?

zooba

invoke GetModuleHandle, 0
invoke LoadMenu, eax, IDM_MENU
invoke CheckMenuItem, eax, 9014, MF_CHECKED


LoadMenu takes a module handle to load the resource from. The return value from GetModuleHandle(0) is the current module, the return value from LoadMenu is the hMenu value (so you'll probably want to store eax somewhere else) which you need to use for any menu API function.

Cheers,

Zooba :U

MichaelW

eschew obfuscation

timertik

I checked msdn.

and tried using  this

invoke GetModuleHandle, 0
invoke LoadMenu, hMenu, IDM_MNU
invoke CheckMenuItem,hMenu,9010,MF_CHECKED

but it remains the same state menu item doesn't change to checked

searched msdn for alternatives and couldnt find much


MichaelW

zooba showed you how to code it. The first parameter for LoadMenu is the module handle returned, in EAX, by GetModuleHandle. LoadMenu returns, in EAX, the menu handle that must be passed to CheckMenuItem.
eschew obfuscation

timertik

I understand now that eax holds the value
but when using eax like in his example it doesn't do anything
maybe cause i have the menu in .rc and not using AppendMenu ?

MichaelW

It should work correctly with the handle returned by LoadMenu. Are you sure that IDM_MNU and 9010 are correct?
eschew obfuscation

timertik

yeah here they are:
#define IDM_MNU 9000
#define IDM_AUTOST 9010
#define IDM_OPTIONS 9102


the menu in .rc
IDM_MNU MENUEX DISCARDABLE
BEGIN
POPUP "File",IDM_FILE
BEGIN
......
......
......
END
POPUP "Settings",IDM_OPTIONS
BEGIN
......
......
......
MENUITEM "Autostart",IDM_AUTOST
END
POPUP "Help",IDM_HELP
BEGIN
.....
END
END

MichaelW

And IDM_MNU is defined the same in the ASM source?
eschew obfuscation

timertik


ramguru

How about this
invoke GetMenu, hWin
invoke GetSubMenu, eax, x ; zero based File - 0, Settings - 1, Help - 2
invoke CheckMenuItem, eax, 9010, MF_BYCOMMAND+MF_CHECKED

MichaelW

What values are the 3 functions returning, starting with GetModuleHandle?
eschew obfuscation

timertik

        PUSH 0
        CALL GetModuleHandleA

        eax==00400000   
   
        PUSH 02328h
        PUSH EAX
        CALL LoadMenuA

        eax = 69FD0247
             
        PUSH 8
        PUSH 02332h
        PUSH EAX
        CALL CheckMenuItem                 
       
        eax == 00000000


untrimmed selection with comments

0040141A   .  6A 00                 PUSH 0                                         ; /pModule = NULL
0040141C   .  E8 AF220000           CALL <JMP.&kernel32.GetModuleHandleA>          ; \GetModuleHandleA
00401421   .  68 28230000           PUSH 2328                                      ; /RsrcName = 2328
00401426   .  50                    PUSH EAX                                       ; |hInst
00401427   .  E8 38220000           CALL <JMP.&user32.LoadMenuA>                   ; \LoadMenuA
0040142C   .  6A 08                 PUSH 8                                         ; /Flags = MF_BYCOMMAND|MF_ENABLED|MF_CHECKED|MF_STRING
0040142E   .  68 32230000           PUSH 2332                                      ; |ItemId = 2332 (9010.)
00401433   .  50                    PUSH EAX                                       ; |hMenu
00401434   .  E8 A7210000           CALL <JMP.&user32.CheckMenuItem>               ; \CheckMenuItem