Jump to content
Sign in to follow this  
Zachlr

How to check the state of a menu item

Recommended Posts

Zachlr

I want to check the state (checked or unchecked) of a (technically, sub)menu item in a GUI that wasn't created by an AutoIt script. Take Notepad for example, how do I check whether "Word-Wrap" is checked or unchecked? I'm not sure if this is possible with AutoIt, but if so, please tell me how to do it.

Thanks,

Zach

Share this post


Link to post
Share on other sites
Zachlr

Thanks. I should be able to figure something out from there. I don't think to look in the UDF help file.

Share this post


Link to post
Share on other sites
Alexandra

Try the example for _GUICtrlMenu_GetItemChecked(). It's just 2 numbers you need to change to check the "Word-Wrap" instead of "Open".

Hi, I have the same problem, I need to reach state of some menu items, and it seems that _GUICtrlMenu_GetItemChecked() doesn't work correct.

When I tried this example with item "Word wrap", it doesn't work, it returns state ""False", though state is checked.

Run("Notepad.exe")
    WinWaitActive("[CLASS:Notepad]")
    $hWnd = WinGetHandle("[CLASS:Notepad]")
    $hMain = _GUICtrlMenu_GetMenu($hWnd)
    $hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 2)
    
    $iIndex = _GUICtrlMenu_FindItem ($hFile, "Word wrap")
        MsgBox(4096, "Information", "Index for Help Menu: " & $iIndex)
    
    ; Check menu item
    Writeln("Word wrap is checked: " & _GUICtrlMenu_GetItemChecked($hFile, $iIndex))

What I do wrong?

Share this post


Link to post
Share on other sites
AdmiralAlkex

Are you running Windows 7? Because I'm and I have the same problem that you are describing.

I don't know why it happens, but it seem to work if the menu is displayed BEFORE you do GetItemChecked(), like this:

ControlSend("[CLASS:Notepad]", "", "", "!o")
ControlSend("[CLASS:Notepad]", "", "", "{ALT}")
; Check menu item
Writeln("Word Wrap is checked: " & _GUICtrlMenu_GetItemChecked($hFile, Number($iIndex)))

(not very fancy but you get my point)

Share this post


Link to post
Share on other sites
Alexandra

Are you running Windows 7? Because I'm and I have the same problem that you are describing.

I don't know why it happens, but it seem to work if the menu is displayed BEFORE you do GetItemChecked(), like this:

ControlSend("[CLASS:Notepad]", "", "", "!o")
ControlSend("[CLASS:Notepad]", "", "", "{ALT}")
; Check menu item
Writeln("Word Wrap is checked: " & _GUICtrlMenu_GetItemChecked($hFile, Number($iIndex)))

(not very fancy but you get my point)

No, I'm using WinXP sp3.

Yes, if item was shown before I get it's status, GetItemChecked() works. It can be current solution for my work...

It seems like this function works correct only for those items, that aren't intended for checked, for example File, Open, Paste etc. And for those items, that really can be checked/unchecked it doesn't work!

Edited by Alexandra

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×