JohnWang Posted November 10, 2007 Posted November 10, 2007 Hi, This must be very simple but I just can't figure it out. Does GUICtrlSetOnEvent works with Picture Control? I already set the OnEventMode to 1, If it does work, where did I do wrong in my code? Any Help is appreciated. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=Diva #AutoIt3Wrapper_Compression=4 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.8.1 Author: Removed Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here ;This is a project to create a mobile management unit with basic human/machine interactions. ;Includes #include <GUIConstants.au3> #include <File.au3> #include <string.au3> ;AutoIt specific Options Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) ;HotKeys ;Delcarations Dim $title, $guiPanWidth, $guiPanHeight, $guiPanHandle, $guiPanFrame ;General Declarations Dim $guiBtnSM, $guiBtnTB, $guiBtnSI, $guiBtnMC, $guiBtnCP, $guiBtnMD, $guiBtnTools, $guiBtnOpt ;Gui Botton handles for Bottons: Start Menu, TaskBar, System Info, My Computer, My Control Panel, My Documents, Tools, and Options respectively ;Variables $title = "The Pan 0.0" $guiPanWidth = 300 $guiPanHeight = 400 ;Functions Titles ;Misc. Info. ;Program Starts - Identification starts here. $guiPanHandle = GUICreate($title,$guiPanWidth,$guiPanHeight,-1,-1,$WS_POPUP,$WS_EX_DLGMODALFRAME) GUISetOnEvent($GUI_EVENT_CLOSE, "PanelEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "PanelEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "PanelEvents") ;Setting up the look for The Pan GuictrlCreatePic("BkgrdDrkOliveGrn.jpg",0,0,$guiPanWidth,$guiPanHeight,-1,$GUI_WS_EX_PARENTDRAG) $guiPanFrame = GUICtrlCreateLabel("",25,0,$guiPanWidth - 60,$guiPanHeight) ;Center Background color piece GuiCtrlSetBkColor(-1,0x006432); Set the color of the label manually: Dark Green GuiCtrlCreateLabel("",25,0,$guiPanWidth - 60,40) GuiCtrlSetBkColor(-1,0xFFFFFF) GuiCtrlCreateLabel("",25,$guiPanHeight - 40,$guiPanWidth - 60,40) GuiCtrlSetBkColor(-1,0xFFFFFF) ;The User interactables: Bottons Using Picture Controls ;Left Side(4) GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent($GUI_EVENT_PRIMARYDOWN,"StartMenu") GUICtrlCreatePic("Botton ImageHolder.jpg",5,40,15,30) GUICtrlSetOnEvent(-1,"Shortcuts") GUICtrlCreatePic("Botton ImageHolder.jpg",5,75,15,30) GUICtrlSetOnEvent(-1,"TaskBar") GUICtrlCreatePic("Botton ImageHolder.jpg",5,110,15,30) GUICtrlSetOnEvent(-1,"SystemInfo") ;Right Side(5) GUICtrlCreatePic("Botton ImageHolder.jpg",$guiPanWidth - 30,5,20,40) GUICtrlCreatePic("Botton ImageHolder.jpg",$guiPanWidth - 30,50,20,40) GUICtrlCreatePic("Botton ImageHolder.jpg",$guiPanWidth - 30,95,20,40) GUICtrlCreatePic("Botton ImageHolder.jpg",$guiPanWidth - 30,140,20,40) GUICtrlCreatePic("Botton ImageHolder.jpg",$guiPanWidth - 30,185,20,40) ;The labels which are going to become the core of the program GUISetState(@SW_SHOW) StartMenu() while 1 Sleep(10000) ; Idling for 4 seconds Exit WEnd ;Functions Func QuickLaunchLoad() EndFunc Func StartMenuLoad() EndFunc Func ShortCutLoad() EndFunc Func CoreCreate() ;creates the center labels for the shortcuts and startmenu items EndFunc Func StartMenu() Msgbox(0,"Working:","StartMenu") EndFunc Func Shortcuts() EndFunc Func TaskBar() EndFunc Func SystemInfo() EndFunc Func PanelEvents() 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) EndSelect EndFunc
Nahuel Posted November 11, 2007 Posted November 11, 2007 (edited) No, you see this is wrong: GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent($GUI_EVENT_PRIMARYDOWN,"StartMenu") GUICtrlSetOnEvent requires a control ID as first parameter. $GUI_EVENT_PRIMARYDOWN is a constant. It is returned byGUIGetMsg() for example. So, the 'event' that would trigger the StartMenu() function is a click on the pic control. This is how it works: GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent(-1,"StartMenu") Edited November 11, 2007 by Nahuel
JohnWang Posted November 11, 2007 Author Posted November 11, 2007 (edited) No, you see this is wrong: GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent($GUI_EVENT_PRIMARYDOWN,"StartMenu") GUICtrlSetOnEvent requires a control ID as first parameter. $GUI_EVENT_PRIMARYDOWN is a constant. It is returned byGUIGetMsg() for example. So, the 'event' that would trigger the StartMenu() function is a click on the pic control. This is how it works: GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent(-1,"StartMenu") Oops, that was my trial and error while I was looking at the scripts on the froum seeing if I can figure it out before having to ask. It should be like the second example posted, but as you can see with my other GuiCtrlSetOnEvents, I tried it already and it doesn't work. You need to use GUIGetCursor to interact with it.There is GUIGetCursorInfo, I don't see GUiGetCursor in the help file, also isn't it a hassle having to compare the mouse coordinates to find out which botton I am clicking... is there easier solution? Edited November 11, 2007 by JohnWang
Generator Posted November 11, 2007 Posted November 11, 2007 My mistake, here is the logic by using GUIGetCursorInfo If the Mouse is over the picture control, and Left mouse button is clicked, event happen, just pull a loop to check that.
martin Posted November 11, 2007 Posted November 11, 2007 Oops, that was my trial and error while I was looking at the scripts on the froum seeing if I can figure it out before having to ask. It should be like the second example posted, but as you can see with my other GuiCtrlSetOnEvents, I tried it already and it doesn't work. There is GUIGetCursorInfo, I don't see GUiGetCursor in the help file, also isn't it a hassle having to compare the mouse coordinates to find out which botton I am clicking... is there easier solution? I think it won't work the way you're doing it because of a misunderstanding of what the code is doing. When you say GUICtrlSetOnEvent(-1,"StartMenu") it doesn't mean that the last control will be used to run the fiunction "StartMenu", it means when the event -1 occurs it will run the startMenu function. What you have to do is use the ID of the control, and to get that assign a variable to it like this $Pic1 = GUICtrlCreatePic("Botton ImageHolder.jpg",5,5,15,30) GUICtrlSetOnEvent($Pic1,"StartMenu") Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
therks Posted November 11, 2007 Posted November 11, 2007 (edited) No, the -1 approach should work, it refers to last created control. *Edit: For most controls anyway, doesn't work with Menu controls.#include <GUIConstants.au3> Opt('GUIOnEventMode', 1) $gui = GUICreate('', 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateButton('Hi', 5, 5, 50, 20) GUICtrlSetOnEvent(-1, '_Button') GUICtrlCreatePic('C:\windows\winnt.bmp', 5, 30, 100, 100) GUICtrlSetOnEvent(-1, '_Picture') GUISetState() While 1 WEnd Func _Button() MsgBox(0, '', 'Button pushed.') EndFunc Func _Picture() MsgBox(0, '', 'Picture clicked.') EndFunc Func _Exit() Exit EndFunc$GUI_EVENT_PRIMARYDOWN is a GUI event and as such is for use with GUISetOnEvent, not GUICtrlSetOnEvent.*Note: I can actually run my example, so I know it's working fine. What version of AutoIt are you running? I have 3.2.9.9. Edited November 11, 2007 by Saunders My AutoIt Stuff | My Github
JohnWang Posted November 11, 2007 Author Posted November 11, 2007 (edited) No, the -1 approach should work, it refers to last created control. *Edit: For most controls anyway, doesn't work with Menu controls. #include <GUIConstants.au3> Opt('GUIOnEventMode', 1) $gui = GUICreate('', 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit') GUICtrlCreateButton('Hi', 5, 5, 50, 20) GUICtrlSetOnEvent(-1, '_Button') GUICtrlCreatePic('C:\windows\winnt.bmp', 5, 30, 100, 100) GUICtrlSetOnEvent(-1, '_Picture') GUISetState() While 1 WEnd Func _Button() MsgBox(0, '', 'Button pushed.') EndFunc Func _Picture() MsgBox(0, '', 'Picture clicked.') EndFunc Func _Exit() Exit EndFunc $GUI_EVENT_PRIMARYDOWN is a GUI event and as such is for use with GUISetOnEvent, not GUICtrlSetOnEvent. *Note: I can actually run my example, so I know it's working fine. What version of AutoIt are you running? I have 3.2.9.9. Woah, that's weird, your code works just fine on my machine as well....d*mn, I hate these kind of errors, now I have to look at all the codes more carefully and completely just to figure out what went wrong. Thank you so much, at least now I know it's my fault and it should be working. EDIT: Alright Guys, thank you very much for the help, I have figure out what went wrong, GuiCtrlSetState(-1,$GUI_DISABLE) was needed on the picture which I had set as background to prevent the two picture controls from overlaping. Edited November 11, 2007 by JohnWang
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