Jump to content

automating a context menu?


Recommended Posts

howdy

I couldn't find existing any clues in the forums so here's my question:

I want to right-click on an item in a SysTreeView to bring up the context menu and then select the first item in the menu. I have tried to use ControlClick - while I can send a left-click to select the tree-item in question I cannot seem to pop its menu on a right-click.

Here's my code:

$vic = wingethandle("C:")
controlfocus($vic, "", "SysTreeView321")
winactivate($vic)
; this works - selects tree-item
controlclick($vic, "", "SysTreeView321", "left", 1, 36, 9)
; this doesn't seem to do anything
controlclick($vic, "", "SysTreeView321", "right", 1, 36, 9)

Using the MouseClick function I get the desired effect but that relies on absolute positioning of the parent window. What would be best is if I could search for the required item's text, get the coords and then click - is that possible?

cheers

mark

Link to post
Share on other sites

howdy

I couldn't find existing any clues in the forums so here's my question:

I want to right-click on an item in a SysTreeView to bring up the context menu and then select the first item in the menu. I have tried to use ControlClick - while I can send a left-click to select the tree-item in question I cannot seem to pop its menu on a right-click.

Here's my code:

$vic = wingethandle("C:")
controlfocus($vic, "", "SysTreeView321")
winactivate($vic)
; this works - selects tree-item
controlclick($vic, "", "SysTreeView321", "left", 1, 36, 9)
; this doesn't seem to do anything
controlclick($vic, "", "SysTreeView321", "right", 1, 36, 9)

Using the MouseClick function I get the desired effect but that relies on absolute positioning of the parent window. What would be best is if I could search for the required item's text, get the coords and then click - is that possible?

cheers

mark

Maybe try

controlclick($vic, "", "[CLASS:SysTreeView321; INSTANCE:1]", "right")
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 post
Share on other sites
  • 1 month later...

Hello morkk,

Here's an example of clicking on the first context-menu item using Calculator as the application.

Run( "Calc.exe" )
WinWaitActive( "Calculator" )

; show 'What's This?' context menu over '2'
$controlPos = ControlGetPos( "[ACTIVE]", "", "[TEXT:2]" )
ControlFocus( "[ACTIVE]", "", "[TEXT:2]" )
ControlClick( "[ACTIVE]", "", "[TEXT:2]", "Right" )

; click on the first item in the context menu
WinWait( "[CLASS:#32768]" )
$winPos = WinGetPos( "[CLASS:#32768]" )
MouseClick( "Left", $winPos[0] + ( $winPos[2] /2 ), $winPos[1] + 10 )

Zach...

Link to post
Share on other sites

Hello morkk,

Here's an example of clicking on the first context-menu item using Calculator as the application.

Run( "Calc.exe" )
WinWaitActive( "Calculator" )

; show 'What's This?' context menu over '2'
$controlPos = ControlGetPos( "[ACTIVE]", "", "[TEXT:2]" )
ControlFocus( "[ACTIVE]", "", "[TEXT:2]" )
ControlClick( "[ACTIVE]", "", "[TEXT:2]", "Right" )

; click on the first item in the context menu
WinWait( "[CLASS:#32768]" )
$winPos = WinGetPos( "[CLASS:#32768]" )
MouseClick( "Left", $winPos[0] + ( $winPos[2] /2 ), $winPos[1] + 10 )

Zach...

Thanks for the example, zfisherdrums. I see that you are using MouseClick with screen coordinates. Is there any way to get at the actual contents of the context menu? I used _WinAPI_EnumWindowsPopup to get the menu handle, but subsequent calls to _GUICtrlMenu_GetItemCount and _GUICtrlMenu_GetMenuHeight return values I don't expect (-1 and 0). Am I missing something, or do the _GUICtrlMenu functions not work with context menus?

I know that Auto3Lib had functions that automated context menus... is there a way to do that with the latest AutoIt?

Link to post
Share on other sites

I looked at exact same API functions before settling on the bulky Mouse Move option. I was unsuccessful as you were at obtaining the menu contents using the current WinAPI include.

That is not to say it isn't possible - I believe it is. It just requires someone with more experience/knowledge/ingenuity than I have for today.

Zach...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...