Jump to content
Sign in to follow this  
Swimming_Bird

Right click on a checkbox control

Recommended Posts

Swimming_Bird

This is the question i was really forumlating fo rmy other post.

I was wondering how i would go about registering a right click on a checkbox control (text et all)

Share this post


Link to post
Share on other sites
rakudave

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...

Share this post


Link to post
Share on other sites
Swimming_Bird

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

Share this post


Link to post
Share on other sites
rakudave

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

Share this post


Link to post
Share on other sites
Swimming_Bird

thats perfect thanks so much

Share this post


Link to post
Share on other sites
Swimming_Bird

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

Share this post


Link to post
Share on other sites
Swimming_Bird

what confuses me is why it wont even call the function. maybe the guicreate is screwed up or something on a second run. i'm guessing that somehow i make it so the guigetmsg isnt grabbing from the correct gui

Share this post


Link to post
Share on other sites
Swimming_Bird

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

Share this post


Link to post
Share on other sites
Swimming_Bird

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:

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  

×