Sign in to follow this  
Followers 0
dushkin

Selecting a context menu item

5 posts in this topic

#1 ·  Posted (edited)

Hi,
 
 Following my question >here, how do I select a menu item according to its text?
 
 I tried the following (please see also comments embedded):

 

If WinExists("[CLASS:#32768") Then

    $hWnd = WinGetHandle("[CLASS:#32768") ;ContextMenu
    $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)

    If _GUICtrlMenu_IsMenu($hMenu) Then
        ConsoleWrite("$menuItemText = " & $menuItemText & @CRLF) ;That is the text I am searching in the menu..

        $menuItemsCount = _GUICtrlMenu_GetItemCount($hMenu)
        ConsoleWrite("$menuItemsCount = " & $menuItemsCount & @CRLF)

        For $i = 0 To $menuItemsCount - 1 ;By the way I tried with FindItem and failed..
            $itemText = _GUICtrlMenu_GetItemText($hMenu, $i)
            ConsoleWrite("$itemText = " & $itemText & @CRLF)

            If $itemText = $menuItemText Then

                Sleep(1000)
                ConsoleWrite("{ENTER}")
                Send("{ENTER}") ;Well, this wouldn't work of course because I didn't select an item. I think I could use here something like "selectItem (text) " before the "ENTER"
                Return True
            EndIf
        Next

        ConsoleWrite("Didn't find " & $menuItemText & " in menu" & @CRLF)
        Return False
    EndIf
EndIf

 

 
Thanks!

Edited by Melba23
Added tags

Share this post


Link to post
Share on other sites



dushkin,

The only way I can get it to fire is like this:

#include <WindowsConstants.au3>
#include "SendMessage.au3"
#Include <GuiMenu.au3>

Global $sRequired_Text = "Select All"

While 1

    If WinExists("[CLASS:#32768]") Then
        $hWnd = WinGetHandle("[CLASS:#32768]")
        $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
        If _GUICtrlMenu_IsMenu($hMenu) Then
            $iCount = _GUICtrlMenu_GetItemCount($hMenu)
            For $iIndex = 0 To $iCount - 1
                Local $sText = _GUICtrlMenu_GetItemText($hMenu, $iIndex)
                If $sText = $sRequired_Text Then
                    $aPos = _GUICtrlMenu_GetItemRect($hWnd, $hMenu, $iIndex)
                    $iOldOpt = Opt("MouseCoordMode", 0)
                    MouseClick("primary", $aPos[0], $aPos[1], 1, 20) ; Adjust the speed to suit
                    Opt("MouseCoordMode", $iOldOpt)
                EndIf
            Next
        EndIf
    EndIf

    Sleep(10)

WEnd
But there must be something more elegant. I will keep looking - or maybe someone else will put us both right! :D

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks Mel.

 Well, your code really helped me, but I had to modify the Mosue click position.

 With your code, it try to click one item above the desired and left of it, meaning it didn't really clicked the Item.

 So I modified the line to 

MouseClick("primary", $aPos[0] + 100, $aPos[1] + 20, 1, 20) 

 and then it was ok, but the question is if this is the correct way? (and it is not!)

 How to perorm this task without manualy modifying the position values?

 Thanks!

Share this post


Link to post
Share on other sites

dushkin,

I have no idea why it does not click in the correct place for you - as you can see I changed the MouseCoordMode mode to the current window, which should be the popup holding the context menu. It certainly worked for me when I tried it within SciTE. What you have done is the logical way to correct the position, but I am afraid I cannot explain why it is not moving to the right place automatically. :wacko:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

i think it should be:

MouseClick("primary", $aPos[0] + ($aPos[2] - $aPos[0]) / 10, $aPos[1] + ($aPos[3] - $aPos[1]) / 2, 1, 20)

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