Jump to content

help with putting items in a gui window


Recommended Posts

@kor,

If you have chosen to go with the GUI Event methods, then the following template may help you. It's what I start all of my GUI's with.

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;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 ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

;Window Variables
Enum $ID_winHEIGHT, $ID_winWIDTH, $ID_winMAIN, $ID_winTITLE, $ID_winMAX
Global $g_arrWin[$ID_winMAX]
;Control Variables
Enum $ID_btnOPTIONS, $ID_btnHELP, $ID_btnEXIT, $ID_conMAX
Global $g_arrCon[$ID_conMAX]

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;---*** 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 ***---
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$g_arrWin[$ID_winHEIGHT] = 300
$g_arrWin[$ID_winWIDTH]  = 300
$g_arrWin[$ID_winTITLE]  = "Template - OnEventMode"

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

;Main GUI Creation
$g_arrWin[$ID_winMAIN]      = GUICreate($g_arrWin[$ID_winTITLE], $g_arrWin[$ID_winWIDTH], $g_arrWin[$ID_winHEIGHT])
;Main Options
$g_arrCon[$ID_btnOPTIONS]   = GUICtrlCreateButton("Options", 5, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20)
;Main Help
$g_arrCon[$ID_btnHELP]      = GUICtrlCreateButton("Help", 103, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20)
;Main Exit
$g_arrCon[$ID_btnEXIT]      = GUICtrlCreateButton("Exit", 201, ($g_arrWin[$ID_winHEIGHT] - 25), 94, 20)

;Disable Options and Help until added
GUICtrlSetState($g_arrCon[$ID_btnOPTIONS], $GUI_DISABLE)
GUICtrlSetState($g_arrCon[$ID_btnHELP], $GUI_DISABLE)

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

;GUI Events Handled by _GUIEventHandler()
GUICtrlSetOnEvent($g_arrCon[$ID_btnOPTIONS], "_GUIEventHandler")
GUICtrlSetOnEvent($g_arrCon[$ID_btnEXIT], "_GUIEventHandler")
GUICtrlSetOnEvent($g_arrCon[$ID_btnHELP], "_GUIEventHandler")

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

GUISetState(@SW_SHOW, $g_arrWin[$ID_winMAIN])

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

While 1
    Sleep(100)
WEnd

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

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $g_arrCon[$ID_btnEXIT]
            _TerminateApp()
        Case $g_arrCon[$ID_btnOPTIONS]
        Case $g_arrCon[$ID_btnHELP]
    EndSwitch
EndFunc

Func _SysEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            If @GUI_WinHandle <> $g_arrWin[$ID_winMAIN] 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 = $g_arrWin[$ID_winTITLE]
        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 = $g_arrWin[$ID_winMAIN] Then
                _TerminateApp()
            Else
                WinActivate($gui_title)
            EndIf
        EndIf
    EndFunc
#endregion Internal Functions

I hope you're getting closer to your goal and learning while achieving...

Jarvis

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