Jump to content

Right click on a checkbox control


Recommended Posts

hmm, what about GUIGetCursorInfo ( [winhandle] )?

If successful, returns a five-element array that containing the mouse cursor information:

$array[0]= X coord (horizontal)

$array[1] = Y coord (vertical)

$array[2] = Primary down (1 if pressed, 0 if not pressed)

$array[3] = Secondary down (1 if pressed, 0 if not pressed)

$array[4] = ID of the control that the mouse cursor is hovering over (or 0 if none)

the array[4] will contain the id of your checkbox...
Link to comment
Share on other sites

how would it register the click? if you right click on a control does it get passed to GUIGetMsg()?

In that case would i just have

If $msg = $control Then<br />   $array = GUIGetCursorInfo ()<br />  If $array[3] Then<br />     _RightClick ()<br />    Else<br />      _LeftClick ()<br /> EndIf<br />EndIf

hrm autoit tags dont seem to be working

$msg = GUIGetMsg()
If $msg = $control Then
    $array = GUIGetCursorInfo ()
    If $array[3] Then
        _RightClick ()
    Else
        _LeftClick ()
    EndIf
EndIf

Would it respond fast enough to register the click?

Edited by Swimming_BIrd
Link to comment
Share on other sites

yes...

here's a working example... :D

#include <GUIConstants.au3>

GUICreate("my gui",100,100,-1,-1)
$checkbox = GUICtrlCreateCheckbox("my checkbox",10,40)
GUISetState()

do
$msg = GUIGetMsg()
$cur = GUIGetCursorInfo()
    If $cur[3] = 1 AND $cur[4] = $checkbox then RightClick()
until $msg = $GUI_EVENT_CLOSE

Func RightClick()
    msgbox(0,"RightClick","you rightclicked on the checkbox!")
    ; ... something else here ...
EndFunc

...hope this helps...

Edited by rakudave
Link to comment
Share on other sites

hrm your script will trigger the rightclick function as many times as i right click. however when i tried to extend your code i broke it somehow. with this it will only triger the select statement the first time i right click

#include <GUIConstants.au3>

$parent = GUICreate("my gui",100,100,-1,-1)
$checkbox = GUICtrlCreateCheckbox("my checkbox",10,40)
GUISetState ( @SW_SHOW , $parent )

While WinActive ( 'my gui' ) Or WinActive ( 'Child' )
    $msg = GUIGetMsg()
    $cur = GUIGetCursorInfo()
    Select
        Case $cur[3] = 1 AND $cur[4] = $checkbox
            MsgBox ( 0 , '' , '' )
            RightClick()
    EndSelect
WEnd

Func RightClick()
    
    $popu = GUICreate ( 'Child' , 100 , 100 , 50 , 50 , $WS_POPUP + $WS_BORDER , -1 , $parent )
    GUICtrlCreateLabel ( 'blahblahblah' , 10 , 10 )
    GUISetState ( @SW_SHOW , $popu )
    While WinActive ( 'Child' )
        Sleep ( 350 )
    WEnd
    GUISetState ( @SW_HIDE , $popu )
EndFunc
Link to comment
Share on other sites

I think i've fixed my problem, however i'm unsure if having a set state for the gui in the while loop is poor coding?

#include <GUIConstants.au3>

$parent = GUICreate("my gui",100,100,-1,-1)
$checkbox = GUICtrlCreateCheckbox("my checkbox",10,40)
GUISetState ( @SW_SHOW , $parent )

While WinActive ( 'my gui' ) Or WinActive ( 'Child' )
    GUISetState ( @SW_SHOW , $parent )
    $msg = GUIGetMsg()
    $cur = GUIGetCursorInfo()
    Select
        Case $cur[3] = 1 AND $cur[4] = $checkbox
            RightClick()
    EndSelect
WEnd

Func RightClick()
    $popu = GUICreate ( 'Child' , 100 , 100 , 50 , 50 , $WS_POPUP + $WS_BORDER , -1 , $parent )
    GUICtrlCreateLabel ( 'blahblahblah' , 10 , 10 )
    GUISetState ( @SW_SHOW , $popu )
    While WinActive ( 'Child' )
        Sleep ( 350 )
    WEnd
    GUISetState ( @SW_HIDE , $popu )
    $popu = ''
EndFunc
Link to comment
Share on other sites

if i didnt have it in there the creation of the other gui would make the GUIGetMsg and GUIGetCursorInfo try and grab info from the wrong gui.

however i just discovered the GUIDelete function :D

i'll see if that allows me not to use that.

EDIT: yup that worked beautifully :wacko:

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...