AustrianOak Posted June 11, 2008 Share Posted June 11, 2008 i have a label in my gui (several of them) and whenever i right click on any one of thema context menu pops up giving me some options. i was wondering if there was a way to set the coordinates of where the context menu pops up? Link to comment Share on other sites More sharing options...
k3v Posted June 11, 2008 Share Posted June 11, 2008 Here's an example of how this can be done... modified from example 1 in the GUICtrlCreateContextMenu help file, and tested. Run the code below and right-click on "My Label"... (it should also work with coords outside of the window) #include <GUIConstants.au3> opt("GUIOnEventMode",1); GUICreate("Test", 300, 200) $label = GUICtrlCreateLabel("My Label", 100, 100, 70, 20) $labelcontext = GUICtrlCreateContextMenu($label) $labelitem = GUICtrlCreateMenuitem("My Context Menu", $labelcontext) GUISetOnEvent($GUI_EVENT_CLOSE,"close") GUISetOnEvent($GUI_EVENT_SECONDARYDOWN,"mymenu");this rightclick won't bring up the menu, but runs the function that sends an additional right-click to the control GUISetState () Func mymenu() $winpos = WinGetPos("Test") $curpos = MouseGetPos() $xtrue = $curpos[0] > ($winpos[0] + 100) and $curpos[0] < ($winpos[0] + 170);these two lines determine whether the mouse is currently over your control $ytrue = $curpos[1] > ($winpos[1] + 130) and $curpos[1] < ($winpos[1] + 150) if $xtrue and $ytrue Then MouseMove($winpos[0],$winpos[1],1);move the mouse to coords of your choice - in this case, top left corner of the window ControlClick("Test","",$label,"Right");a second right-click brings up the context menu where the mouse is. EndIf EndFunc While 1 sleep(10) Wend func close() Exit EndFunc These two lines determine whether the mouse is currently over your control. The values come from your label's coords at creation, but remember to account for the title-bar on your window... (i added 30 to the y values, but it's possible you'll need to play with this value to make sure the target area covers your control completely) $xtrue = $curpos[0] > ($winpos[0] + 100) and $curpos[0] < ($winpos[0] + 170) $ytrue = $curpos[1] > ($winpos[1] + 130) and $curpos[1] < ($winpos[1] + 150) If the $xtrue & $ytrue values are both TRUE, Move the mouse to coords of your choice - in this case, top left corner of the window and send a second right-click to the label to bring up the context menu where the mouse is. if $xtrue and $ytrue Then MouseMove($winpos[0],$winpos[1],1) ControlClick("Test","",$label,"Right") EndIf Note... adding the "speed" parameter to the mousemove makes this behavior occur very quickly, (instantly)... but leaving it off will still work.. you'll just get to watch the mouse wander to its new location before the context menu comes up. Hope this helps! k3v Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now