Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

29 May 2017, 19:19

I have put some thought into this and I think you're going to like this.
I have made all of the Gui events, into functions.
I was inspired to make this because of Tic's Gdip original library.
It's so simplistic to use.

This however just looks like a bunch of mumbo jumbo with tons of useless things.

I'll say one thing. To make multiple Gui windows, you have to do GuiNew() everytime

Code: Select all

/*
	# =====================================================
	# Gui Functions
	# =====================================================
*/


GuiDestroy() {
	Gui, Destroy
	Return
}

GuiNew(Options := "", Title := "") {
	Global
	Gui, New, % Options, % Title
	Return
}

GuiShow(Options := "", Title := "") {
	Global
	Gui, Show, % Options, % Title
	Return
}

GuiColor(Options := "White") {
	Global
	Gui, Color, % Options
	Return
}

GuiMargin(w := 10, h := 10) {
	Global
	Gui, Margin, %w%, %h%
	Return
}

GuiHide() {
	Gui, Hide
	Return
}

GuiFont(Options := "", Font := "Verdana") {
	Gui, Font, % Options, % Font
	Return
}

GuiMenu(MenuHandle := "") {
	Gui, Menu
	Return
}

GuiMini() {
	Gui, Minimize
	Return
}

GuiMax() {
	Gui, Maximize
	Return
}

GuiRes() {
	Gui, Restore
	Return
}

GuiFlash(Var := 1) {
	If (Var = 1) {
		OnOff := ""
	} Else {
		OnOff := "Off"
	}
	Gui, Flash, %OnOff%
	Return
}

GuiSubmit(HideGui := 0) {
	Global
	If (HideGui = 1) {
		Hide := "NoHide"
	} Else If (HideGui = 0) {
		Hide := "NA"
	} Else {
		Hide := ""
	}
	Gui, Submit, %Hide%
	Return
}


/*
	# =====================================================
	# Gui Types
	# =====================================================
*/


GuiButton(Options := "", Text := "Ok") {
	Global
	Gui, Add, Button, % Options, % Text
	Return
}

GuiCheckBox(Options := "", Text := "") {
	Global
	Gui, Add, CheckBox, % Options, % Text
	Return
}

GuiCombobox(Options := "", Text := "One|Two|Three") {
	Global
	Gui, Add, ComboBox, % Options, % Text
	Return
}

GuiDateTime(Options := "", Text := "") {
	Global
	Gui, Add, DateTime, % Options, % Text
	Return
}

GuiDropdownList(Options := "", Text := "One|Two|Three") {
	Global
	Gui, Add, DropDownList, % Options, % Text
	Return
}

GuiEdit(Options := "", Text := "") {
	Global
	Gui, Add, Edit, % Options, % Text
	Return
}

GuiGroupBox(Options := "", Text := "Options") {
	Global
	Gui, Add, GroupBox, % Options, % Text
	Return
}

GuiHotkey(Options := "", Text := "") {
	Global
	Gui, Add, Hotkey, % Options, % Text
	Return
}

GuiListBox(Options := "", Text := "") {
	Global
	Gui, Add, ListBox, % Options, % Text
	Return
}

GuiListView(Options := "", Text := "") {
	Global
	Gui, Add, ListView, % Options, % Text
	Return
}

GuiMonthCal(Options := "", Text := "") {
	Global
	Gui, Add, MonthCal, % Options, % Text
	Return
}

GuiPicture(Options := "", Text := "NotePad.exe") {
	Global
	Gui, Add, Picture, % Options, % Text
	Return
}

GuiProgress(Options := "", Text := 0) {
	Global
	Gui, Add, Progress, % Options, % Text
	Return
}

GuiRadio(Options := "", Text := "") {
	Global
	Gui, Add, Radio, % Options, % Text
	Return
}

GuiSlider(Options := "", Text := 0) {
	Global
	Gui, Add, Slider, % Options, % Text
	Return
}

GuiTab1(Options := "", Text := "One|Two|Three") {
	Global
	Gui, Add, Tab, % Options, % Text
	Return
}

GuiTab2(Options := "", Text := "One|Two|Three") {
	Global
	Gui, Add, Tab2, % Options, % Text
	Return
}

GuiTab3(Options := "", Text := "One|Two|Three") {
	Global
	Gui, Add, Tab3, % Options, % Text
	Return
}

GuiText(Options := "", Text := "Just Some Text.") {
	Global
	Gui, Add, Text, % Options, % Text
	Return
}

GuiTreeView(Options := "") {
	Global
	Gui, Add, TreeView, % Options
	Return
}

GuiUpDown(Options := "", Text := 0) {
	Global
	Gui, Add, UpDown, % Options, % Text
	Return
}

GuiCustom(Options := "", Text := "") {
	Global
	Gui, Add, Custom, % Options, % Text
	Return
}

GuiActiveX(Options := "", Text := "") {
	Global
	Gui, Add, ActiveX, % Options, % Text
	Return
}


/*
	# =====================================================
	# Misc Functions I made for automation. :P
	# =====================================================
*/


MB(Message := "Press Ok to Continue.", Title := "", Type := 0, Time := "") {
	MsgBox, % Type, % Title, % Message, % Time
	Return
}

ToolTip(Message, Time := 3000) {
	ToolTip %Message%
	SetTimer, RemToolTip, %Time%
	Return

	RemToolTip:
	SetTimer, RemToolTip, Off
	ToolTip
	Return
}

TransparentWin(Amount := 255) {
	WinGetTitle, Window
	WinSet, Transparent, %Amount%, %Window%
	Return
}

/*
	Library concluded
*/
I have made an example of using some of these commands in an example script:

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%
#Include %A_ScriptDir%\Func Lib.ahk

GuiNew("+ToolWindow +Caption")
GuiEdit("w75 h25 vEdit -WantReturn")
GuiButton("w75 h25 gSend vSend", "Send")
GuiButton("w75 h25 gClose", "Close")
GuiShow("", "New")
Return

Esc::
GuiClose:
GuiEscape:
Close:
ExitApp
Return

Send:
GuiSubmit(1)
MB(Edit)
Return
The miscellaneous functions are for a quick and easy tool.
If you have any questions, suggestions, or comments, please feel free to speak up! :D
Enjoy your summer everyone! :dance:

Edit: Fixed the Gui Destroy giving an error.
Last edited by Delta Pythagorean on 30 May 2017, 01:00, edited 1 time in total.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

TAC109
Posts: 1099
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

29 May 2017, 23:10

GuiFlash looks incomplete...
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 00:59

TAC109 wrote:GuiFlash looks incomplete...
My bad on that. I just now fixed it up.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 06:38

It only supports one Gui though. Also not sure why you're making some of the functions global?
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 14:37

Run1e wrote:It only supports one Gui though. Also not sure why you're making some of the functions global?
It supports multiple, as I've said you have to do GuiNew() every time.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 15:30

What if I want to manage two guis at the same time?
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 15:45

Run1e wrote: What if I want to manage two guis at the same time?
You can use hwnd. Although I haven't found a solid way to do it without hwnd to be honest. Sorry on my part.
Delta Pythagorean wrote: I'll say one thing. To make multiple Gui windows, you have to do GuiNew() everytime
Again, sorry about that. I've attempted and looked into using A_ThisGui, but I always got an error.
If you know a way I could do this, feel free to tell me.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 15:48

Here's an example of multiple Guis:
Proof.PNG
Proof.PNG (86.55 KiB) Viewed 2675 times
Just use GuiNew() everytime.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 16:12

I may make this library into classes and objects.
Similar to how Tic did his Gdip library.

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat

A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 16:22

It only supports one GUI. Your GuiDestroy function, for example, will always destroy the default GUI - if you try:

Code: Select all

!x::
GuiDestroy()
return
I'm pretty sure it won't work since the GUI window itself is set as the thread's last found window only when a GUI thread launched it, which is not the case here: a hotkey triggers the subroutine.
Delta Pythagorean wrote:I may make this library into classes and objects.
You have a good intuition: consider create a class instead, or if it doesn't talk to you yet a base object - you'll find below a simple example. This way, you'll can, for example, destroy a GUI specifying the target (e.g. MyGUITest.destroy()) - using internally HWND as you pointed out.

Code: Select all

GUI := Object()
GUI.instances := [] ; an empty array to be filled with each GUI instance.
GUI.__New := Func("_GuiNew") ; GUI.__New set here the function to be called when the script creates a new GUI instance by means of the 'new' keyword .
GUI.show := Func("_GuiShow")
GUI.hide := Func("_GuiHide")
GUI.add := Func("_GuiAdd")

; ~~~~~~~~~~~~~~~~~~~~~~~ example ~~~~~~~~~~~~~~~~~~~~~~~
MyGUI := new GUI() ; create a new instance of GUI (this calls _GuiNew below)
MsgBox % MyGUI.AHKID ; check for MyGUI AHKID property (set within _GuiNew)
MyOtherGUI := new GUI() ; create another one
MsgBox % MyOtherGUI.AHKID ; check its own AHKID
MyGUI.add("DropDownList", "w300", "a|b|c|d") ; this calls _GuiAdd
MyGUI.show("w400 h400", "1") ; this calls _GuiShow
MyOtherGUI.add("Edit", "w400 h200", "blabla")
MyOtherGUI.show("AutoSize", "2")

!x::
MyOtherGUI.hide()
sleep, 2000
MyOtherGUI.show("AutoSize")
return

; ============ functions ============
; 'this' is automatically passed at the beginning of the parameter list when the function is called using 'GUI.key' where GUI is an instance of GUI
; created by means of the new keyword and where 'key''s value is a function reference.
; 'this' contains a reference to the instance derived from the GU object; and upon which you can operate within the function.
_GuiNew(this, __options:="", __title:="") {
local __HWND
	GUI, New, % "+hwnd__HWND " . __options, % __title
	this.AHKID := "ahk_id " . (this.HWND:=__HWND)
return GUI.instances[__HWND] := this
}
_GuiAdd(this, __controlType, __options:="", __params:="") {
local __HWND
GUI, % this.HWND . ":Add", % __controlType, % __options .  " hwnd__HWND", % __params
return __HWND
}
_GuiShow(this, __options:="", __title:="") {
	if (__title <> "")
		GUI, % this.HWND . ":Show", % __options, % __title
	else GUI, % this.HWND . ":Show", % "NA " . __options
}
_GuiHide(this) {
GUI, % this.HWND . ":Hide"
}
; ...

[EDIT] by the way, if you intend to create a class instead I think take a look at Run1e one's will be very helpfull.
my scripts
User avatar
runie
Posts: 304
Joined: 03 May 2014, 14:50
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 17:03

Yeah there are a few gui wrappers including mine out there.
User avatar
Delta Pythagorean
Posts: 627
Joined: 13 Feb 2017, 13:44
Location: Somewhere in the US
Contact:

Re: Gui Function Library (And a few Misc) Inspired by Tic's Gdip Library

30 May 2017, 20:20

I understand what you're point is. Thank you all for your co-operation in this library. I'll look into Run1e's library as you said.
Again thank you all, this small project will be even greater with your help! :D

[AHK]......: v2.0.12 | 64-bit
[OS].......: Windows 11 | 23H2 (OS Build: 22621.3296)
[GITHUB]...: github.com/DelPyth
[PAYPAL]...: paypal.me/DelPyth
[DISCORD]..: tophatcat


Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 131 guests