Jump to content

Can GUICtrlSetState click a menu item?


LWC
 Share

Recommended Posts

None of GUICtrlSetState's states seem to click menu items. $GUI_DEFBUTTON puts the chosen item in bold but that's it.

For example, if I have a menu called "File" (with "Open" and "Save"), I want a method to open the "File" tab.

I realize I can use WinMenuSelectItem or use "&File" with Send("!F"). But those are external methods. Is there an internal method for AutoIt's own internal GUIs?

Thanks!

Edited by LWC
Link to comment
Share on other sites

Why on earth would you want to try to do that with a control you already have full control over? If you want to "click" a menu item on a menu you created, just have your script do whatever that menu item does.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Which is completely different from what you asked in your original post.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You asked me "why on Earth" so I've answered to satisfy you. Can we get back to the original question? I just want the user to see the updated menu after they click the menu item that updates the menu.

Edited by LWC
Link to comment
Share on other sites

  • Moderators

LWC,

As far as I know there is no way to open a menu "internally", but here is one way you might want to use to do what you want

Here is a workaround solution - see below for a programatic method: :graduated:

#include <GUIConstantsEx.au3>
#Include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$mFilemenu = GUICtrlCreateMenu("File")
$mTestitem = GUICtrlCreateMenuItem("Test", $mFilemenu)
$mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu)
$mHelpmenu = GUICtrlCreateMenu("?")
$mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu)

GUISetState()

$hMenu = _GUICtrlMenu_GetMenu($hGUI)
$iCount = _GUICtrlMenu_GetItemCount($hMenu) - 1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $mExititem
            Exit
        Case $mTestitem
            ReOpenMenu("File")
        Case $mAboutitem
            MsgBox(0, "Solved", "That was not too hard!")
    EndSwitch

WEnd

Func ReOpenMenu($sText)

    ; Change the menu item text
    GUICtrlSetData($mTestitem, "New Title")

    ; Move through the menu items to match the passed title
    For $i = 0 To $iCount
        If $sText = _GUICtrlMenu_GetItemText($hMenu, $i) Then
            ; Get item location
            $aItemPos = _GUICtrlMenu_GetItemRect($hGUI, $hMenu, $i)
            ; Click to open the menu
            MouseClick("primary", $aItemPos[0] + 10, $aItemPos[1] + 10, 1, 0)
        EndIf
        ExitLoop
    Next

EndFunc

I hope that helps. :(

M23

Edit: Because George insisted - see below. :D

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hey M8

You should change that to MouseClick("primary", $aItemPos[0] + 10, $aItemPos[1] + 10, 1, 0) in case the user is a leftie.

M23 - 2

GEO - 15

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

George,

As usual you are absolutely correct - it must come with advanced age, and of course I am not there quite yet. :(

I have done as you command and amended the post above, O Great (and Aged) One. :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Internally, this uses $WM_MENUSELECT with $MF_MOUSESELECT (0x8000). You need to get the handle with GUICtrlGetHandle and then use GUICtrlSendMessage. No example yet, sorry.

Edit: This demonstrates it: Just recreate the message and it send it to your GUI (by handle).

Edited by Manadar
Link to comment
Share on other sites

  • Moderators

LWC,

This is how you open a menu programatically (thanks to JamesBrooks for the hint :D ):

#include <GUIConstantsEx.au3>
#Include <GuiMenu.au3>

$hGUI = GUICreate("Test", 500, 500)

$mFilemenu = GUICtrlCreateMenu("File")
$mTestFileitem = GUICtrlCreateMenuItem("Test File", $mFilemenu)
$mTestHelpitem = GUICtrlCreateMenuItem("Test Help", $mFilemenu)
$mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu)
$mHelpmenu = GUICtrlCreateMenu("Help")
$mAboutitem = GUICtrlCreateMenuItem("About", $mHelpmenu)

GUISetState()

$hMenu = _GUICtrlMenu_GetMenu($hGUI)
$iCount = _GUICtrlMenu_GetItemCount($hMenu) - 1
ConsoleWrite("Count: " & $iCount & @CRLF)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $mExititem
            Exit
        Case $mTestFileitem
            _OpenMenu("File")
        Case $mTestHelpitem
            _OpenMenu("Help")
        Case $mAboutitem
            MsgBox(0, "Solved", "That was a bit harder!")
    EndSwitch

WEnd

Func _OpenMenu($sText)

    ; Sleep to demonstrate the menus close and reopen
    Sleep(1000)

    ; Move through the menu items to match the passed title
    For $i = 0 To $iCount
        ConsoleWrite("Text: " & _GUICtrlMenu_GetItemText($hMenu, $i) & @CRLF)
        If $sText = _GUICtrlMenu_GetItemText($hMenu, $i) Then
            ConsoleWrite($i & @CRLF)
            ; Get submenu handle
            $hSubMenu = _GUICtrlMenu_GetItemSubMenu($hMenu, $i)
            ; Get item location
            $aItemPos = _GUICtrlMenu_GetItemRect($hGUI, $hMenu, $i)
            ; Reopen the menu
            _GUICtrlMenu_TrackPopupMenu($hSubMenu, $hGUI, $aItemPos[0], $aItemPos[3])
            ExitLoop
        EndIf
    Next

EndFunc

I hope it does what you want. :graduated:

Manadar,

I tried lots of messages but none of them worked even though they matched the ones sent when I clicked on the menu: :(

GUI creation:

GUI: 0x0015090A
Menu: 0x010308A7

Sending message = _SendMessage($hGUI, $WM_MENUSELECT, 0x80900000, $hMenu):

MouseSelect
hWnd: 0x0015090A
$iMsg: 011F
$wParam: 0x80900000
$lParam: 0x010308A7

Popup
hWnd: 0x0015090A
$iMsg: 011F
$wParam: 0x80900000
$lParam: 0x010308A7

Message Sent.

Mouse clicked on menu:

MouseSelect
hWnd: 0x0015090A
$iMsg: 011F
$wParam: 0x80900000
$lParam: 0x010308A7

Popup
hWnd: 0x0015090A
$iMsg: 011F
$wParam: 0x80900000
$lParam: 0x010308A7

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...