Sign in to follow this  
Followers 0
azure

[RESOLVED] How Do I Click Context Menu and Submenu Items?

10 posts in this topic

#1 ·  Posted (edited)

Here's what I'm trying to do. I posted as a reply to an OLDER post... I'm part of the way to where I want to be.

RIGHT CLICK TASKBAR (the part of XP that's between the start menu and the system tray)

CHOOSE TOOLBAR (Accellerator = T, typically first index in the right click menu)

UNCHECK "Windows Desktop Search" (you can apply this to any of the options in there. checking or unchecking).

I've spent most of the day today searching the forums and no one seems to have a solution to this that I can actually understand. I've seen many many posts on creating your own context menu, but that's not what I want. This is a pre-existing menu.

Here's the code I have so far:

#include <GuiToolbar.au3>

Opt("WinTitleMatchMode", 4)

$hWnd   = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "ToolbarWindow322")
$aRect = _GUICtrlToolbar_GetButtonRect($hWnd, _GUICtrlToolbar_IndexToCommand($hWnd, _GUICtrlToolbar_ButtonCount($hWnd)-1))
$tpoint = DllStructCreate("int X;int Y")
DllStructSetData($tpoint, "X", $aRect[0])
DllStructSetData($tpoint, "Y", $aRect[3])
$pPoint = DllStructGetPtr($tPoint)
DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", $pPoint)
MouseClick("right", DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 1, 1)

This right clicks the taskbar for me. Now I need to TRAVERSE the menu that's brought up, choose TOOLBAR, then UNCHECK WINDOWS DESKTOP SEARCH.

Edited by azure

Share this post


Link to post
Share on other sites



Hi,

For traverse menu simply use send function,hope this could help you

Send("{UP}");go at top of first item
Send("{RIGHT}");go to menu
;etc..

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

Hi,

For traverse menu simply use send function,hope this could help you

Send("{UP}");go at top of first item
Send("{RIGHT}");go to menu
;etc..
Thank you.. but the SEND command is sort of unreliable. For instance, what if they have more options in their context menu? or more toolbars to choose from? then i'm just picking the wrong one. i need to attack this programatically rather than using brute force key sends.

Share this post


Link to post
Share on other sites

Any ideas? How do I Find text within a context menu and click it?

Share this post


Link to post
Share on other sites

Any ideas? How do I Find text within a context menu and click it?

The traymenu you want to traverse is an autoit script ?


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

The traymenu you want to traverse is an autoit script ?

No. I typed out what I'm looking for. right click your taskbar at the bottom of your screen, go to toolbars, then go to the submenu.. that's what i want.. but to do it automatically without using sendkeys. There has to be a way to "findtext" in that menu, click the container of said text, etc.

Share this post


Link to post
Share on other sites

Bump.

Anyone?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try enabling / disabling the toolbar, see what in the registry changes, using a tool like RegShot

You could then code in the proper registry changes into your script.

The next step would be getting Explorer to recognize the toolbar changes without a restart. I don't know how to do this in AutoIT, surely it can be done with a DLL call or something, but using the tool Nircmd

You can try the commands:

nircmd sysrefresh
nircmd shellrefresh
Edited by TurionAltec

Share this post


Link to post
Share on other sites

Try enabling / disabling the toolbar, see what in the registry changes, using a tool like RegShot

You could then code in the proper registry changes into your script.

The next step would be getting Explorer to recognize the toolbar changes without a restart. I don't know how to do this in AutoIT, surely it can be done with a DLL call or something, but using the tool Nircmd

You can try the commands:

nircmd sysrefresh
nircmd shellrefresh
Thank you, but I've tried that already. The changes made are to a dword value that determines what toolbars are in effect. This dword, however, isn't documented. No one's able to determine what part of it makes what work. I've googled the heck out of it, which is why I fell back to an autoit solution.

Thanks for the link to nircmd.. That'll be useful for future scripts! :)

Any other ideas?

Share this post


Link to post
Share on other sites

For anyone else interested, here's how the final script coded.

I used someone elses system tray popup script and fiddled around with it until I got it to do what I want.

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GuiToolbar.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiMenu.au3>
#include <WinAPI.au3>
#Include <Misc.au3>

;_Singleton("TrayMenuTest", 0)

Opt("MustDeclareVars", 1)

Global $gaPopups[1][3] = [[0, 0]]
Global $hMenu, $hParent

Func OpenMenu()
    Local $hWnd, $aRect, $tPoint, $pPoint
    $hWnd   = ControlGetHandle("[CLASS:Shell_TrayWnd]", "", "ToolbarWindow322")
    $aRect = _GUICtrlToolbar_GetButtonRect($hWnd, _GUICtrlToolbar_IndexToCommand($hWnd, _GUICtrlToolbar_ButtonCount($hWnd)-1))
    $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", $aRect[0])
    DllStructSetData($tpoint, "Y", $aRect[3])
    $pPoint = DllStructGetPtr($tPoint)
    DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", $pPoint)
    MouseClick("right", DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 1, 1)
EndFunc

OpenMenu()
    Sleep(100)
    _Lib_PopupScan()
    If $gaPopups[0][0] > 0 Then
        Decode()
    EndIf
    SLEEP(100)
    _Lib_PopupScan()
    If $gaPopups[0][0] > 0 Then
        Decode()
    EndIf

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func Decode()
    Local $iI, $iType
    Local $ahwnd[2]

    For $iI = 1 To $gaPopups[0][0]
        $ahwnd[0] = _Lib_PopupGetHwnd($iI) ; menu hwnd
        $iType = _Lib_PopupGetType($iI) ; menu/toolbar/tooltip
        $ahwnd[1] = _Lib_PopupGetParent($iI) ; parent hwnd
        If $hMenu <> $ahwnd[0] Or $hParent <> $ahwnd[1] Then
            $hMenu = $ahwnd[0]
            $hParent = $ahwnd[1]
            If _GUICtrlMenu_IsMenu($hMenu) And IsHWnd($hParent) Then
                Select
                    Case $iType = 1
                        ModShowMenu($hMenu, $hParent)
                EndSelect
            EndIf
        EndIf
    Next
   
    Return $ahwnd
EndFunc   ;==>Decode

Func ClickMe($hParent, $hMenu, $iI)
    Local $aRect, $tPoint, $pPoint
    $aRect = _GUICtrlMenu_GetItemRect($hParent, $hMenu, $iI)
    
    $tpoint = DllStructCreate("int X;int Y")
    DllStructSetData($tpoint, "X", $aRect[0])
    DllStructSetData($tpoint, "Y", $aRect[3])
    $pPoint = DllStructGetPtr($tPoint)
    ;DllCall("User32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", $pPoint)
    ;MouseMove(DllStructGetData($tPoint, "X")+20, DllStructGetData($tPoint, "Y")-14)
    MouseClick("left", DllStructGetData($tPoint, "X")+20, DllStructGetData($tPoint, "Y")-14, 1, 1)

EndFunc

Func ModShowMenu($hMenu, $hParent)
    Local $iCount
    $iCount = _GUICtrlMenu_GetItemCount($hMenu)
    ;ConsoleWrite("+Parent handle .........: " & $hParent & @CRLF)
    ;ConsoleWrite("+Menu handle ...........: " & $hMenu & @CRLF)
    ;ConsoleWrite("+Menu item count .......: " & $iCount & @CRLF)
    If _GUICtrlMenu_FindItem($hMenu, "Tile Windows Horizontally", True) > 0 Then ClickMe($hParent, $hMenu, _GUICtrlMenu_FindItem($hMenu, "Toolbar",True))
    If _GUICtrlMenu_FindItem($hMenu, "Quick Launch", True) > 0 Then ClickMe($hParent, $hMenu, _GUICtrlMenu_FindItem($hMenu, "Windows Search", True))
EndFunc

Func _Lib_PopupGetParent($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][2]
EndFunc   ;==>_Lib_PopupGetParent

Func _Lib_PopupGetType($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][1]
EndFunc   ;==>_Lib_PopupGetType

Func _Lib_PopupGetHwnd($iIndex = 1)
    _Lib_PopupWait()
    Return $gaPopups[$iIndex][0]
EndFunc   ;==>_Lib_PopupGetHwnd

Func _Lib_PopupScan()
    Local $iI, $sClass, $hWnd, $hMenu
    ReDim $gaPopups[1][3]
    $gaPopups[0][0] = 0
    ReDim $winapi_gaWinList[64][2]
    $winapi_gaWinList[0][0] = 0
    $winapi_gaWinList[0][1] = 64
    _WinAPI_EnumWindowsPopup()
    For $iI = 1 To $winapi_gaWinList[0][0]
        $hWnd = $winapi_gaWinList[$iI][0]
        $sClass = $winapi_gaWinList[$iI][1]
        Select
            Case $sClass = "#32768"
                $hMenu = _SendMessage($hWnd, $MN_GETHMENU, 0, 0)
                _Lib_PopupAdd($hMenu, 1, $hWnd)
            Case $sClass = "ToolbarWindow32"
                _Lib_PopupAdd($hWnd, 2, _WinAPI_GetParent($hWnd))
            Case $sClass = "ToolTips_Class32"
                _Lib_PopupAdd($hWnd, 3, _WinAPI_GetParent($hWnd))
        EndSelect
    Next
EndFunc   ;==>_Lib_PopupScan

Func _Lib_PopupWait()
    Local $iLoop = 0
    While $iLoop < 50
        If $gaPopups[0][0] > 0 Then Return
        Sleep(100)
        _Lib_PopupScan()
        $iLoop += 1
    WEnd
    ConsoleWrite("Timeout waiting for popup window to appear" & @CRLF)
EndFunc   ;==>_Lib_PopupWait

Func _Lib_PopupAdd($hWnd, $iType, $hParent)
    Local $iCount
    $gaPopups[0][0] += 1
    $iCount = $gaPopups[0][0]
    ReDim $gaPopups[$iCount + 1][3]
    $gaPopups[$iCount][0] = $hWnd
    $gaPopups[$iCount][1] = $iType
    $gaPopups[$iCount][2] = $hParent
EndFunc   ;==>_Lib_PopupAdd

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