Jump to content
Sign in to follow this  
quick_sliver007

right clicking controls

Recommended Posts

quick_sliver007

How do I know if a control is right clicked in a gui? I try this but it is not right.

#include <GUIConstants.au3>

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)

$parent1 = GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "SpecialEvents");Here;;;;;;;;;;;;


$ok1 = GUICtrlCreateButton ("OK",  10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

$cancel1 = GUICtrlCreateButton ( "Cancel",  0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")

GUISetState(@SW_SHOW)


While 1
    Sleep(10)
Wend

Func OKPressed()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc

Func CancelPressed()
    MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc

Func SpecialEvents()    

    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            Exit
            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
        
        Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $ctrlfocus = ControlGetFocus($parent1,"parent1")
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)    
    EndSelect   
EndFunc

.

Share this post


Link to post
Share on other sites
SmOke_N

What's not working? I get the message box with whatever has focus at the moment. I would change this:

$ctrlfocus = ControlGetFocus($parent1,"parent1")
To this:
$ctrlfocus = ControlGetFocus($parent1)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
quick_sliver007

What's not working? I get the message box with whatever has focus at the moment. I would change this:

$ctrlfocus = ControlGetFocus($parent1,"parent1")
To this:
$ctrlfocus = ControlGetFocus($parent1)
Thank you, but that did not do it either. It only gets the button that was last left click, both ways.

.

Share this post


Link to post
Share on other sites
syberschmo

I found a workaround.... I'm sure theres a better way. Insert this under the @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN

Opt("MouseCoordMode", 0)

$pos = MouseGetPos()
            Select
                Case $pos[1]<75 AND $pos[1]>50
                    
                    Select
                        Case $pos[0]<50 AND $pos[0]>8
                            ControlFocus("Parent1", "", 3)
                        Case $pos[0]<108 AND $pos[0]>58
                            ControlFocus("Parent1", "", 4)
                    EndSelect
            EndSelect
            $ctrlfocus = ControlGetFocus($parent1)
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)

Share this post


Link to post
Share on other sites
quick_sliver007

I found a workaround.... I'm sure theres a better way. Insert this under the @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN

Opt("MouseCoordMode", 0)

$pos = MouseGetPos()
            Select
                Case $pos[1]<75 AND $pos[1]>50
                    
                    Select
                        Case $pos[0]<50 AND $pos[0]>8
                            ControlFocus("Parent1", "", 3)
                        Case $pos[0]<108 AND $pos[0]>58
                            ControlFocus("Parent1", "", 4)
                    EndSelect
            EndSelect
            $ctrlfocus = ControlGetFocus($parent1)
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)
Thats a big work around, thanks for the help though. I don't think there is any good way to do this. There may be a DLL way to do this, but I am no good with DLLs.

.

Share this post


Link to post
Share on other sites
SmOke_N

Thank you, but that did not do it either. It only gets the button that was last left click, both ways.

It wasn't intended to do "anything", it was a visual correction I thought you should make because if the title ever changed, then that function would not work at all. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
syberschmo

I re-visited this problem and I came up with a really simple solution that I can't believe I missed. Is this what you are looking for?

(in the While loop)

Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $pos = GuiGetCursorInfo()
            MsgBox(0, "ControlGetFocus", "ControlGetFocus is " & $pos[4])

$pos[4] is the control that the mouse is hovering over. You could easily give it focus with the code I posted earlier, above.

Regards,

Share this post


Link to post
Share on other sites
quick_sliver007

I re-visited this problem and I came up with a really simple solution that I can't believe I missed. Is this what you are looking for?

(in the While loop)

Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $pos = GuiGetCursorInfo()
            MsgBox(0, "ControlGetFocus", "ControlGetFocus is " & $pos[4])

$pos[4] is the control that the mouse is hovering over. You could easily give it focus with the code I posted earlier, above.

Regards,

Thank you for the help.

.

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  

×