Morag Posted October 18, 2023 Share Posted October 18, 2023 Attempting to discover whether a disabled menu item is disabled or not. Have tried both of _GUICtrlMenu_GetItemEnabled and _GUICtrlMenu_GetItemState. When I use _GUICtrlMenu_GetItemEnabled it returns True to suggest the menu is enabled (when it is not). When I use _GUICtrlMenu_GetItemState, it returns 12, to suggest the menu is disabled (4) and greyed (8) - which it is. I had initially assumed that these were looking at the same thing, but now I don't understand what _GUICtrlMenu_GetItemEnabled is for. Can anyone explain the difference? Cheers, Morag Link to comment Share on other sites More sharing options...
spudw2k Posted October 18, 2023 Share Posted October 18, 2023 (edited) Looking at the GUIMenu.au3 source code, the _GetItemEnabled function is simply calling the _GetItemStateEx function and comparing the result against $MF_DISABLED. Not sure why it returned true if _GetItemState returned 12. With this demo, the functions appear to work as expected. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiMenu.au3> $hGUI = GUICreate("Menu", 240, 90) $hMnuFile = _GUICtrlMenu_CreateMenu() $hMnuFileEnabled = _GUICtrlMenu_AddMenuItem($hMnuFile, "Menu Item #1") $hMnuFileDisabled = _GUICtrlMenu_AddMenuItem($hMnuFile, "Menu Item #2") _GUICtrlMenu_SetItemDisabled($hMnuFile, 1) $hMain = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_AddMenuItem($hMain, "&File", 0, $hMnuFile) _GUICtrlMenu_SetMenu($hGUI, $hMain) $idBtn = GUICtrlCreateButton("Analyze Menu", 74, 20, 100, 30) GUISetState(@SW_SHOW) Do $idMsg = GUIGetMsg() If $idMsg = $idBtn Then AnalyzeMenuState() Until $idMsg = $GUI_EVENT_CLOSE Func AnalyzeMenuState() $sMsg = "" For $iX = 0 to _GUICtrlMenu_GetItemCount($hMnuFile)-1 $sMsg &= "Menu Item Index: " & $iX & " [" $sMsg &= _GUICtrlMenu_GetItemText($hMnuFile, $iX) $sMsg &= ((_GUICtrlMenu_GetItemEnabled($hMnuFile, $iX) = True) ? " is Enabled" : " is Disabled") & "]" & @CRLF Next Msgbox(0, "Menu State", $sMsg) EndFunc Edited October 18, 2023 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Morag Posted October 20, 2023 Author Share Posted October 20, 2023 (edited) Hmm, do you think that fact that I am interrogating a pre-existing GUI rather than building a GUI with AutoIt makes any difference? Here's an example using the ubiquitous Notepad application that demonstrates what I am seeing. #include <GuiMenu.au3> TestNPMenu() Func TestNPMenu() Local $hWnd, $hMain, $hEdit, $index ; Open Notepad Run("notepad.exe") $hWnd = WinWaitActive("[CLASS:Notepad]", "", 10) If $hWnd == 0 Then ConsoleWriteError("Could not detect Notepad window"&@CRLF) return EndIf WinActivate($hWnd) Send("!e") ; Open Edit menu Send("{ESC}{ESC}") ; close it again $hMain = _GUICtrlMenu_GetMenu($hWnd) $hEdit = _GUICtrlMenu_GetItemSubMenu($hMain, 1) $index = _GUICtrlMenu_FindItem($hEdit, "Undo", true) $MenuEnabled = _GUICtrlMenu_GetItemEnabled($hEdit, $index) $MenuState = _GUICtrlMenu_GetItemState($hEdit, $index) If $MenuEnabled == True Then ConsoleWrite("Undo menu is enabled"&@CRLF) Else ConsoleWrite("Undo menu is disabled"&@CRLF) Endif ConsoleWrite("Undo menu has state "&$MenuState&@CRLF) EndFunc When I run this, the following is written to stdout. Undo menu is enabled Undo menu has state 12 As noted earlier, 12 is disabled (4) and greyed (8) which of course the Undo menu indeed is until you do anything in the Notepad application. Does this script show the same for you? Cheers, Morag Edited October 20, 2023 by Morag Link to comment Share on other sites More sharing options...
spudw2k Posted October 20, 2023 Share Posted October 20, 2023 As is, when I run it, I get Undo menu is enabled Undo menu has state 0 I am running Windows 11, and it appears that Win 11 notepad is not using the Win32 Menu control anymore. i did try it with Regedit and I got the same results as you, enabled & 12. strange. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Solution InnI Posted October 20, 2023 Solution Share Posted October 20, 2023 On 10/18/2023 at 9:07 AM, spudw2k said: the _GetItemEnabled function is simply calling the _GetItemStateEx function and comparing the result against $MF_DISABLED It looks like the functions _GUICtrlMenu_GetItemEnabled and _GUICtrlMenu_GetItemDisabled should use $MFS_DISABLED spudw2k 1 Link to comment Share on other sites More sharing options...
Morag Posted October 20, 2023 Author Share Posted October 20, 2023 16 hours ago, spudw2k said: I am running Windows 11, and it appears that Win 11 notepad is not using the Win32 Menu control anymore. Oh dear - the ubiquitous Notepad application that all the examples for AutoIt use is not so ubiquitous any more! Need to find something else to use to demonstrate things! 11 hours ago, InnI said: It looks like the functions _GUICtrlMenu_GetItemEnabled and _GUICtrlMenu_GetItemDisabled should use $MFS_DISABLED This sounds like a correction is needed somewhere. So I guess I continue to use _GUICtrlMenu_GetItemState since that is working for me. Thanks all! Cheers, Morag Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now