-
Notifications
You must be signed in to change notification settings - Fork 0
/
libGUI.au3
154 lines (104 loc) · 4.52 KB
/
libGUI.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.14.2
Author: Sean Zeng
Script Function:
Server for passing license information to network clients via udp.
Graphical user interface Script
MIT LICENSE
Control Fucntion WIKI https://www.autoitscript.com/autoit3/docs/functions/GUICtrlUpdate%20Management.htm
Create Funtction WIKI https://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateEdit.htm
#ce ----------------------------------------------------------------------------
#include-once
#include <GUIConstantsEx.au3> ; GUI Functions
#Include <GUIEdit.au3> ; GUI Edit
#include <EditConstants.au3> ; GUICtrlCreateEdit Func for editing GUI Constants
#Include <ScrollBarConstants.au3> ; GUI Scroll Settings
#include <Date.au3> ; Date and time
#include <MsgBoxConstants.au3> ; MSG boxes
#include <WindowsConstants.au3> ; Windows Fourms
; Program variables, Dim will reuse/overwrite global variables if set
Dim $g_bCloseConfim = False ; Show Close Confirm MsgBox
Dim $g_bShowDate = False ; Show date in console
Dim $g_MainWinW = 500 ; Main window width
Dim $g_MainWinH = 600 ; Main window height
;-- For running gui standalone, testing purposes
If Not IsDeclared("sProgramName") Then
Global $sProgramName = "!NOTE! GUI TEST ONLY MODE"
$bTestMode = True ; A way for close loop to choose how to handle exit
startGUI()
For $i = 0 to 40
GUIConsoleOut("GUI standalone TEST")
Next
GUIConsoleOut("fjfkl;jel;kfjwlek;jfl;weqjl;fjlew;jfkljwelkqjfklwqjel;fjwelq;kfjl;wejfklewfl;weqnfkewmlckewjklqflkwe;fckl;wejflkjwlek")
While 1
Sleep(100)
WEnd
EndIf
;-----------------------------GUI-----------------------------
Func startGUI()
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
; --- Interface Modules ---
Local $mainGUI = GUICreate($sProgramName, $g_MainWinW, $g_MainWinH) ; X Width, Y Width
; -- Labels --
Global $g_labelConsole = GUICtrlCreateLabel("Console Output", 20, 40) ;x,y
Global $g_labelIP = GUICtrlCreateLabel("Server: Not Ready", 10, $g_MainWinH - 20, $g_MainWinW - 40)
; -- Buttons --
Local $iOKButton = GUICtrlCreateButton("Test Console", 380, 20, 100, 30) ; X Cord, Y Cords, X Width, Y Width
Local $iClientsButton = GUICtrlCreateButton("Clients", 380, 380, 100, 30)
; -- Text Fields --
Global $g_idOutputEdit = GUICtrlCreateEdit("", 20, 60, $g_MainWinW - 40, 300, $GUI_SS_DEFAULT_EDIT + $ES_READONLY) ; X Cord, Y Cords, X Width, Y Width
; -- Check Boxes --
Global $g_idCheckbox = GUICtrlCreateCheckbox("Show Date", 20, 360)
; GUI Interrupts to run functions on click
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
GUICtrlSetOnEvent($iOKButton, "OKButton") ; Testing purposes currently
GUICtrlSetOnEvent($g_idCheckbox, "DATECheckbox") ; redundant for no since we use _IsChecked($GUIid)
; Control GUI module data
GUICtrlSetState($g_idCheckbox, $g_bShowDate)
;Show GUI
GUISetState(@SW_SHOW, $mainGUI)
EndFunc
; -- Control Functions --
; Scrolls and adds text to console output
; Thanks to Melba23 for scroll code on Autoit Fourms
Func GUIConsoleOut($sText)
$iEnd = StringLen(GUICtrlRead($g_idOutputEdit))
_GUICtrlEdit_SetSel($g_idOutputEdit, $iEnd, $iEnd)
_GUICtrlEdit_Scroll($g_idOutputEdit, $SB_SCROLLCARET)
GUIConsoleOutID($g_idOutputEdit, $sText) ; Calls the function below with ID of edit box and text
EndFunc
; Adds text with date and time if checked to the defined GUI edit box
Func GUIConsoleOutID($gID, $sText)
Local $sOutput = _NowTime(5); 5 = 24 hr + sec, 3 = default
If _IsChecked($g_idCheckbox) Then
$sOutput = $sOutput & " " & _NowDate() ; Add date if checked
EndIf
$sOutput = $sOutput & " - " & $sText; Append log text to end of output string
GUICtrlSetData($gID,$sOutput & @LF, 1)
EndFunc
Func OKButton()
; Note: At this point @GUI_CtrlId would equal $iOKButton,
; and @GUI_WinHandle would equal $hMainGUI
; MsgBox($MB_OK, "GUI Event", "Ok was clicked")
GUIConsoleOut("Test")
EndFunc ;==>OKButton
Func CLOSEButton()
; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE,
; and @GUI_WinHandle would equal $hMainGUI
If $g_bCloseConfim Then
$ans = MsgBox($MB_OKCANCEL, "Confirm", "Are you sure you want to close license server?", 5)
If $ans = 1 Then
Exit
EndIf
Else
Exit
EndIf
EndFunc ;==>CLOSEButton
Func DATECheckbox()
$g_bShowDate = _IsChecked($g_idCheckbox)
EndFunc
; -- GUI Control Helper functions --
Func _IsChecked($idControlID)
Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc ;==>_IsChecked
;-----------------------------END_GUI-----------------------------