Hypertrophy Posted December 12, 2009 Share Posted December 12, 2009 I know this is probably a really basic question but how to I get the text of the menu item I created in my AutoIt GUI and change it? Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 12, 2009 Share Posted December 12, 2009 (edited) It's not quite so basic. GuiCtrlRead() and ControlGetText() won't do it. You can use the GuiMenu.au3 UDF functions for it, though: #include <GuiMenu.au3> ; Note: $hGUI is the handle to the GUI/Window of interest $hMenu = _GUICtrlMenu_GetMenu($hGUI) $iCnt = _GUICtrlMenu_GetItemCount($hMenu) $sMsg = "There are " & $iCnt & " items in the menu:" & @CRLF For $n = 0 To $iCnt - 1 $sMsg &= @TAB & $n & ": " & _GUICtrlMenu_GetItemText($hMenu, $n) & @CRLF Next MsgBox(64, "Test", $sMsg) Edited December 12, 2009 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Hypertrophy Posted December 12, 2009 Author Share Posted December 12, 2009 It's not quite so basic. GuiCtrlRead() and ControlGetText() won't do it. You can use the GuiMenu.au3 UDF functions for it, though: #include <GuiMenu.au3> ; Note: $hGUI is the handle to the GUI/Window of interest $hMenu = _GUICtrlMenu_GetMenu($hGUI) $iCnt = _GUICtrlMenu_GetItemCount($hMenu) $sMsg = "There are " & $iCnt & " items in the menu:" & @CRLF For $n = 0 To $iCnt - 1 $sMsg &= @TAB & $n & ": " & _GUICtrlMenu_GetItemText($hMenu, $n) & @CRLF Next MsgBox(64, "Test", $sMsg) Maybe I was misunderstood. I have created a context menu with items and a specific item I need to get the text of. Link to comment Share on other sites More sharing options...
martin Posted December 13, 2009 Share Posted December 13, 2009 (edited) Maybe I was misunderstood. I have created a context menu with items and a specific item I need to get the text of. What PsaltyDS showed is correct, except that you need to use the handle for your context menu like this $iCnt = _GUICtrlMenu_GetItemCount(GUICtrlGetHandle($menu[0][0])) $sMsg = "There are " & $iCnt & " items in the menu:" & @CRLF For $n = 0 To $iCnt - 1 $sMsg &= @TAB & $n & ": " & _GUICtrlMenu_GetItemText(GUICtrlGetHandle($menu[0][0]), $n) & @CRLF Next MsgBox(64, "Test", $sMsg) You can change the text for an item like this GUICtrlSetData($menu[0][2],"some new choice") Edited December 13, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 14, 2009 Share Posted December 14, 2009 Maybe I was misunderstood. I have created a context menu with items and a specific item I need to get the text of.Misunderstood? Where was a context menu mentioned? What PsaltyDS showed is correct, except that you need to use the handle for your context menu like this $iCnt = _GUICtrlMenu_GetItemCount(GUICtrlGetHandle($menu[0][0])) $sMsg = "There are " & $iCnt & " items in the menu:" & @CRLF For $n = 0 To $iCnt - 1 $sMsg &= @TAB & $n & ": " & _GUICtrlMenu_GetItemText(GUICtrlGetHandle($menu[0][0]), $n) & @CRLF Next MsgBox(64, "Test", $sMsg) You can change the text for an item like this GUICtrlSetData($menu[0][2],"some new choice")Did you get some code in a PM or something? Where did we get that the control IDs were in 2D $menu array? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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