NDog Posted January 11, 2012 Posted January 11, 2012 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
LarsJ Posted January 11, 2012 Posted January 11, 2012 You can do something like this expandcollapse popup#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 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
LarsJ Posted January 11, 2012 Posted January 11, 2012 Change "LeftMouseButton" to "RightMouseButton", sorry. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
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