Jump to content

GUISetOnEvent


Recommended Posts

Are there more options for GUISetOnEvent ? i've found that you run into big problems when using 2 or more GUI's in one application, for example, Parent GUI, and Child GUI, if you're using GUISetOnEvent you can't detect whether it came from the parent or the child (To my knowlege), now this is necessary mainly in one option, $GUI_EVENT_CLOSE, say you close the child, it will close both. I did end up writing Case $msg[0] = $blah but i have found that GUICtrlSetOnEvent($blah, 'blahFunc') is MUCH MUCH faster, i'm talking noticeable !

So if you know how to fix this please let me know! If there isn't a way out there know, I hope the devs add in something to detect which gui it came from and execute the func desired.

Link to comment
Share on other sites

Try using this template I have created. It works great with multiple GUI's.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;Program Name:  Template - OnEventMode
;Description:   Template for OnEventMode GUI scripts
;Filename:      Template - OnEventMode.au3
;Used With:     
;Created by:    Jarvis J Stubblefield (support "at" vortexrevolutions "dot" com)
;Created on:    06/20/2006
;Modified on:   
;Modified by:   
;Version:       0.0.2
;Copyright:     Copyright (C) 2006 Vortex Revolutions. All Rights Reserved.
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Declare Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $wHeight, $wWidth, $wMain            ;Window variables
Global $wTitle                              ;Window variables II

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Preprocessor ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1) ;Set GUI to ONEvent Mode.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** File Installations ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Registry Information ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Command Line Options ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#cs UNCOMMENT FOR COMMANDLINE!
If $CmdLine[0] > 0 Then
    If StringRight($CmdLine[1], 4) = ".ext" Then
        _SomeFunc($CmdLine[1])
    Else
        _ErrorMsg("Incorret file extension. Please try again.")
        _TerminateApp()
    EndIf
EndIf
#ce

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Variables ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$wHeight = 300
$wWidth  = 300
$wTitle  = "Template - OnEventMode"

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Creation ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Main GUI Creation
$wMain  = GUICreate($wTitle, $wWidth, $wHeight)
;Main Options
$btnMOptions    = GUICtrlCreateButton("Options", 5, ($wHeight - 25), 94, 20)
;Main Help
$btnMHelp       = GUICtrlCreateButton("Help", 103, ($wHeight - 25), 94, 20)
;Main Exit
$btnMExit       = GUICtrlCreateButton("Exit", 201, ($wHeight - 25), 94, 20)

;Disable Options and Help until added
GUICtrlSetState($btnMOptions, $GUI_DISABLE)
GUICtrlSetState($btnMHelp, $GUI_DISABLE)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Set Events ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;GUI Events Handled by _GUIEventHandler()
GUICtrlSetOnEvent($btnMOptions, "_GUIEventHandler")
GUICtrlSetOnEvent($btnMExit, "_GUIEventHandler")
GUICtrlSetOnEvent($btnMHelp, "_GUIEventHandler")

;System Events Handled by _SysEventHandler()
GUISetOnEvent($GUI_EVENT_CLOSE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_RESTORE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_PRIMARYUP, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_RESIZED, "_SysEventHandler", $wMain)
GUISetOnEvent($GUI_EVENT_DROPPED, "_SysEventHandler", $wMain)

GUISetState(@SW_SHOW, $wMain)

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Main Program Loop ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

While 1
    Sleep(100)
WEnd

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** GUI Event Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $btnMExit
            _TerminateApp()
        Case $btnMOptions
        Case $btnMHelp
    EndSwitch
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            If @GUI_WinHandle <> $wMain Then
                _TerminateGUI(@GUI_WinHandle)
            Else
                _TerminateApp()
            EndIf
        Case $GUI_EVENT_MINIMIZE
        Case $GUI_EVENT_RESTORE
        Case $GUI_EVENT_MAXIMIZE
        Case $GUI_EVENT_PRIMARYDOWN
        Case $GUI_EVENT_PRIMARYUP
        Case $GUI_EVENT_SECONDARYDOWN
        Case $GUI_EVENT_SECONDARYUP
        Case $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_RESIZED
        Case $GUI_EVENT_DROPPED
    EndSwitch
EndFunc

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** Define Functions ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

#region --- Internal Functions
    ;Displays an error message to the user, and optionally times out.
    Func _ErrorMsg($message, $time = 0)
        MsgBox(48 + 262144, "Error!", $message, $time)
    EndFunc

    ;Function to be used to terminate the application. (Clean up Application)
    Func _TerminateApp()
        Exit
    EndFunc
    
    ;This function is to be used with programs that have multiple GUI's and
    ;will optionally terminate application if called incorrectly on the main
    ;GUI.
    Func _TerminateGUI($gui_hWnd, $gui_title = "")
        If $gui_title = "" Then $gui_title = $wTitle
        If $gui_hWnd = $hSome3rdLayerGUI Then
            ;Do 3rd Layer GUI stuff (for example look at RAS-NEW.au3)
            GUIDelete($gui_hWnd)
        Else
            GUIDelete($gui_hWnd)
            If $gui_hWnd = $wMain Then
                _TerminateApp()
            Else
                WinActivate($gui_title)
            EndIf
        EndIf
    EndFunc
#endregion Internal Functions

It can even handle 3rd level GUI's.

I hope this helps,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Nvm, I think I got it !, Thank you very much for your help

No problem...

You may also want to consider using Functions to create your GUI's that way everything to recreate each GUI is right there in the function. You wont have to worry with hiding it and what not.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

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