Sign in to follow this  
Followers 0
Hypertrophy

Get menu item text of menu item in AutoIt GUI

5 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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? :evil:

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? :evil:

;)


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

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  
Followers 0