Jump to content

Right click label in OnEventMode


NDog
 Share

Recommended Posts

Hi all.

Is there any easy way to right click a label in OnEventMode to return a function? I want to be able to click on a label and do something depending on whether I left click or right click on it. I am grateful for any advice.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 278, 153)
$Pic1 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 2, 276, 148)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp", 80, 48, 132, 44)
GUICtrlSetCursor(-1,0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("Click me!", 80, 48, 132, 44, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Label1, "LabelLeftMouseClicked") ; When left click label
GUICtrlSetOnEvent($Label1, "LabelRightMouseClicked") ; When right click label
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
While 1 ;On event mode GUI
    Sleep(100)
WEnd

Func FormClose()
    Exit
EndFunc
Func LabelLeftMouseClicked()
ConsoleWrite("Left button clicked")
EndFunc
Func LabelRightMouseClicked()
ConsoleWrite("Right button clicked")
EndFunc
Link to comment
Share on other sites

You can do something like this

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <WinAPI.au3>
#include <StaticConstants.au3>
Global $aPos1
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 278, 153)
$Pic1 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\msoobe.jpg", 0, 2, 276, 148)
GUICtrlSetState(-1, $GUI_DISABLE)
$Pic2 = GUICtrlCreatePic("C:\Program Files\AutoIt3\Examples\GUI\Advanced\Images\Green.bmp", 80, 48, 132, 44)
GUICtrlSetCursor(-1,0)
GUICtrlSetState(-1, $GUI_DISABLE)
$Label1 = GUICtrlCreateLabel("Click me!", 80, 48, 132, 44, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetCursor(-1,0)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($Label1, "LabelLeftMouseClicked") ; When left click label
;GUICtrlSetOnEvent($Label1, "LabelRightMouseClicked") ; When right click label
GUISetOnEvent($GUI_EVENT_CLOSE, "FormClose")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "LeftMouseButtonDown")
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "LeftMouseButtonUp")
While 1 ;On event mode GUI
    Sleep(100)
WEnd
Func FormClose()
    Exit
EndFunc
Func LabelLeftMouseClicked()
ConsoleWrite("Left button clicked" & @CRLF)
EndFunc
Func LabelRightMouseClicked()
ConsoleWrite("Right button clicked")
EndFunc
Func LeftMouseButtonDown()
  $aPos1 = GUIGetCursorInfo( $Form1 )
EndFunc
Func LeftMouseButtonUp()
  Local $aPos2 = GUIGetCursorInfo( $Form1 )
  If $aPos1[0] > 80 And $aPos1[0] < 80 + 132 And _
     $aPos1[1] > 48 And $aPos1[1] < 48 + 44  And _
     $aPos2[0] > 80 And $aPos2[0] < 80 + 132 And _
     $aPos2[1] > 48 And $aPos2[1] < 48 + 44 Then _
     ConsoleWrite("Right button clicked" & @CRLF)
EndFunc
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...