Jump to content

Get menu item text of menu item in AutoIt GUI


Recommended Posts

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
Link to comment
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.
Link to comment
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.

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.
Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...