Jump to content

Does GUICtrlSetOnEvent works with Picture Control?


JohnWang
 Share

Recommended Posts

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.

#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
Link to comment
Share on other sites

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 by Nahuel
Link to comment
Share on other sites

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 by JohnWang
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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 by Saunders
Link to comment
Share on other sites

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