here it is all in one script for easy testing
Code:
GUI1 := GUI()
GUI1.Add("Text","Default Text","w500 h200")
GUI1.Show()
o := GUI()
o.Add("Text","Name:")
o.Add("Text","Address1:")
o.Add("Text","Address2:")
o.Add("Edit","Name","","name")
o.Add("Edit","Address1","","address1")
o.Add("Edit","Address2","","address2")
o.Add("Button","Ok","","OK")
o.name.ym := "True"
o.name.w := 200
o.address1.w := 200
o.address2.w := 200
o.OK.g := "ButtonLabel"
o.Show("x600 y50","Enter Your Details")
o2 := GUI() ; Gui Object
o2.Add("Text") ; Add a Text Control
o2.Add("Edit") ; Add an Edit Control
o2.2.v := "MyEdit1" ; set VarName
o2.1.Text := "Gui 2" ; use control index instead of VarName
o2.MyEdit1.Text := "Put Some Text In The Control Now"
; Make All the controls the same size
Loop % o2.ControlCount
o2[A_Index].h := 50, o2[A_Index].w := 400
o2.Resize := "True"
o2.ToolWindow := "True"
o2.Show("x100 y100","Object Test Gui # 2")
o3 := GUI()
o3.Color("Lime")
o3.Add("Text","Default Text","","MyText1")
o3.MyText1.Text := "New Text"
o3.MyText1.h := 100
o3.MyText1.w := 200
o3.Border := "True"
o3.Caption := "False"
o3.Resize := "True"
o3.Show("x50 y500","Object Test Gui # 1")
;=====================
o4 := GUI()
o4.Color("Blue","Yellow")
o4.Add("Text","Some Text 2")
o4.Add("Edit","Type Some **** Shit Here 2")
o4.Add("Button","Wooo 2")
;o4.ToolWindow := "True" ; String true
o4.AlwaysOnTop := "True" ; String true
o4.Show("x200 y200")
Loop, 27 {
o4.Move(A_Index * 20, A_Index * 20)
Sleep, 50
}
o4.2.SetText("Change The Text Now")
Sleep, 2000
o4.2.SetText("Some More New Text")
;o4.Show("x200 y200")
return
ButtonLabel:
o.Submit()
MsgBox % "name: " . o.name.Text . "`n"
. "address1: " . o.address1.Text . "`n"
. "address2: " . o.address2.Text . "`n"
MsgBox % "name: " . name . "`n"
. "address1: " . address1 . "`n"
. "address2: " . address2 . "`n"
Return
Esc::ExitApp
/*
Gui := GUI()
Gui := GUI()
Gui.Color("White")
Gui.Add("Picture", A_WinDir "\system32\ntimage.gif", "x0 y0 h350 w450")
Gui.Add("Button", "Start the Bar Moving", "+Default xp+20 yp+250")
Gui.Add("Progress", "", "vMyProgress w416")
Gui.Add("Text","", "vMyText wp")
Gui.Show()
Esc::ExitApp
ButtonStartTheBarMoving:
Loop, %A_WinDir%\*.*
{
if A_Index > 100
break
;GuiControl,, MyProgress, %A_Index%
Gui.MyProgress.Text := A_Index
GuiControl,, MyText, %A_LoopFileName%
Sleep 50
}
GuiControl,, MyText, Bar finished.
return
GuiClose:
ExitApp
*/
; gui.ahkl
; requires AutoHotkey_L
;requires control.ahkl
; by ahklerner
;version .1 alpha
; This object handles a gui!!!
; intended use is by YOU
/*
Gui := Gui()
;Exposed Functions
Gui.Add(Type[,Text="",Options=""])
Gui.Show([Options=""])
Gui.Submit([Options=""])
Gui.Hide()
Gui.Cancel()
Gui.Destroy()
Gui.Font([Options="",FontName=""])
Gui.Color(WindowColor=""[,ControlColor=""])
Gui.Margin([x="",y=""])
;Exposed Properties
; IMPORTANT the Proprties are set to the STRING True or False, not 0 or 1
Gui.GuiProperty := "True" ; Same as specifying +GuiProperty in the Options
Gui.GuiProperty := "False" ; Same as specifying -GuiProperty in the Options
; Example
Gui.AlwaysOnTop := "True" ; Make Gui AlWaysOnTop
Gui.ToolWindow := "True" ; Make Gui ToolWindow
; The properties exposed in this manner are:
; AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,MaximizeBox,MaximizeBox
; MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
*/
GUI_GetVal(obj, name){
;MsgBox % Name
return obj[name]
}
GUI_SetVal(obj, name, val){
list1 = AlwaysOnTop,Border,Caption,Delimiter,Disabled,Label,LastFound,LastFoundExist,MaximizeBox,MaximizeBox,
,MinimizeBox,MinSize,MaxSize,OwnDialogs,Resize,SysMenu,Theme,ToolWindow
list2=Owner
GuiNum := obj.GuiNum
if name in %list1%
{
if val = False
Gui, %GuiNum%:-%name%
else if val = True
Gui, %GuiNum%:+%name%
}
}
GUI_Delete(obj){
}
GUI_Submit(obj,opts,title){
}
GUI_Call(obj, func, prm0=" ",prm1=" ",prm2=" ",prm3=" ",prm4=" ",prm5=" "){
list1 = Show,Hide,Cancel,Destroy,Font,Color,Margin
loop 6
num := A_Index - 1, VarSetCapacity(prm%num%, -1)
SetWinDelay, -1
GuiNum := obj.GuiNum
if (func = "Add") {
Type := prm0, Text := prm1, Options := prm2, VarName := prm3
c := Control(obj,Type)
VarName = %VarName%
Options = %Options%
Text = %Text%
if VarName {
obj[VarName] := c
c.Options.v := VarName
}
if Options
c.Options.Import(Options)
c.Text := Text ? Text : " "
Return ControlIndex := c.Index
}else if (func = "Show"){
num := obj.ControlCount
;MsgBox % num
Loop % num
{
;MsgBox Create Being Called
num := A_Index
if (obj[num].HasBeenCreated = false)
obj[num].Create()
}
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}else if (func = "Submit"){
;MsgBox % GuiNum
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
num := obj.ControlCount
;MsgBox % num
Loop % num
{
varname := obj[A_Index].Options.v
VarSetCapacity(varname, -1)
varname = %varname%
;varname
if varname
obj[A_Index].Text := GUI_GetGlobal(varname)
else {
hWnd := obj[A_Index].hWnd
ControlGetText, OutputVar, % "ahk_id " . hWnd
obj[A_Index].Text := OutputVar ? OutputVar : " "
}
}
} else if (func = "Move"){
prm0 = %prm0%
prm1 = %prm1%
prm2 = %prm2%
prm3 = %prm3%
hWnd := obj.hWnd
hWnd = %hWnd%
;WinGetTitle, Title, ahk_id %hWnd%
WinGetClass, Class, ahk_id %hWnd%
;MsgBox % Class
;obj.Show("x" . prm0 . " y" . prm1)
WinMove, ahk_id %hWnd%,,%prm0%,%prm1%,%prm2%,%prm3%
}else if func in %list1%
Gui, %GuiNum%:%func%, %prm0%,%prm1%,%prm2%,%prm3%
}
GUI_GetGlobal(varname){
global
VarSetCapacity(varname, -1)
varname = %varname%
Transform, val, Deref,% %varname%
;MsgBox % "VarName: " . varname . "`nVal: " . val
return val
}
GUI(param="¬"){
static COBase
if ((param = "¬")||(!param)){
; get first unused gui number
loop, 99 {
num := A_Index
Gui, %A_Index%:+LastFoundExist
If !WinExist()
break ;
}
param := num
}
If !COBase
COBase := Object("__Get", "GUI_GetVal", "__Set", "GUI_SetVal", "__Delete", "GUI_Delete", "__Call", "GUI_Call")
Gui, %param%:+LastFound
hWnd := WinExist()
return Object("GuiNum", param, "ControlCount", 0, "hWnd", hWnd, "base", COBase)
}
; control.ahkl
; requires AutoHotkey_L
; by ahklerner
;version .1 alpha
; This object handles a gui's controls
; intended use is by gui object... but can be modified to suit other purposes
;
Control_GetVal(obj, name){
if name = hWnd
{
text := obj[name]
;MsgBox % text
VarSetCapacity(text, -1)
return text ? text : " "
}
if name = HasBeenCreated
return obj.HasBeenCreated
;MsgBox % "GetVal: " . name
return obj.Options[name]
}
Control_SetVal(obj, name, val){
if name = hWnd
obj.hWnd := val
else if name = HasBeenCreated
obj.HasBeenCreated := val
else if name = Text
obj.Text := val
else
obj.Options[name]:= val
if name = v
obj.Parent[val] := obj
}
Control_Delete(obj){
MsgBox "Delete"
}
Control_GetClassNN(hWndWindow,hWndControl){
DetectHiddenWindows, On
WinGet, ClassNNList, ControlList, ahk_id %hWndWindow%
Loop, PARSE, ClassNNList, `n
{
ControlGet, hwnd, hwnd,,%A_LoopField%,ahk_id %hWndWindow%
if (hWnd = hWndControl)
return A_LoopField
}
}
Control_SetText(obj,NewText){
if (obj.HasBeenCreated = True) {
hWnd := obj.hWnd
GuiNum := obj.Parent.GuiNum
controlvarname := obj.v
controlvarname = %controlvarname%
if controlvarname
GuiControl, %GuiNum%:, %controlvarname%, %NewText%
else
ControlSetText,, %NewText%,ahk_id %hWnd%
}
obj.Text := NewText
}
Control_GetText(obj,NewText){
if (obj.HasBeenCreated = True) {
hWnd := obj.hWnd
ControlGetText, out,,ahk_id %hWnd%
obj.Text := out
}
return obj.Text
}
Control_Call(obj, func, prm0="¬",prm1="",prm2="",prm3="",prm4="",prm5=""){
loop 6
num := A_Index - 1, VarSetCapacity(prm%num%, -1)
if (func = "Create"){
;MsgBox % obj.Text
Control_Create(obj,obj.Type,obj.Options.ToParam(),obj.Text)
obj.HasBeenCreated := True
}else if (func = "Text"){
prm0 = %prm0%
;GuiNum := obj.Parent.GuiNum
if (prm0 != "¬"){
hWnd := obj.hWnd
ControlSetText,, %prm0%,ahk_id %hWnd%
obj.Text := prm0
}else{
hWnd := obj.hWnd
ControlGetText, out,,ahk_id %hWnd%
obj.Text := out
return out
}
}
}
Control_Create(obj,Type,Opts="",Text=""){
Global
Local GuiNum, hWnd
;MsgBox Create Called
Type = %Type%
Opts = %Opts%
Text = %Text%
GuiNum := obj.Parent.GuiNum
Gui, %GuiNum%:Add, %Type%, %Opts% hWndhWndControl, %Text%
obj.hWnd := hWndControl
;MsgBox % "hWndControl: " . hWndControl
hWndWindow := obj.Parent.hWnd
;MsgBox % "hWndWindow: " . hWndWindow
ClassNN := Control_GetClassNN(hWndWindow,hWndControl)
ClassNN = %ClassNN%
; MsgBox % "New Control ClassNN: " . ClassNN
obj.Parent[ClassNN] := obj
}
Control(Parent,Type){
static COBase
;Local AddCount
If !COBase
COBase := Object( "__Get" , "Control_GetVal" ; default getter
, "__Set" , "Control_SetVal" ; default setter
, "GetText" , "Control_GetText" ; .GetText()
, "SetText" , "Control_SetText" ; .SetText(NewText)
; , "Text" , "Control_Text" ; .Text([NewText])
; , "__Delete" , "Control_Delete"
, "__Call" , "Control_Call")
;MsgBox % "Control():Type " . Type
AddCount := Parent.ControlCount
VarSetCapacity(AddCount, -1)
if !AddCount
AddCount = 0
AddCount++
Control := Object("Type", Type, "Parent", parent,"HasBeenCreated", false, "Index", AddCount, "hWnd", " ", "Text", " ", "Options", opt := options(), "base", COBase)
opt.Parent := Control
Control.Parent.ControlCount := AddCount
Control.Parent[AddCount] := Control
Control.Parent[AddCount] := Control
return Control
}
; options.ahkl
; requires AutoHotkey_L
; by ahklerner
;version .1 alpha
; This object handles a gui's or control's "Options"
; intended use is by control and gui object... but can be modified to suit other purposes
;
Options_Opt(ByRef sOpts,sName,sVal="¬"){
if (sVal = "¬"){ ; get the option
if RegExMatch(sOpts, sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",Match)
return Match1
else
return ""
}
if RegExMatch(sOpts, sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",Match)
sOpts := RegExReplace(sOpts,sName . "=(\+?-?[a-zA-Z0-9\s]*)¬",sName . "=" . sVal . "¬")
else if (sOpts = "¬")
sOpts := sName . "=" . sVal . "¬"
else
sOpts .= sName . "=" . sVal . "¬"
return sOpts
}
Options_GetVal(obj, name){
if name = Parent
return obj.Parent
sOpts := obj.ToStr
return Options_Opt(sOpts,name)
}
Options_SetVal(obj, name, val){
;MsgBox % "options:SetVal`nname:" . name . "`nval:" . val
if name = Parent
return obj.Parent := val
if name = ToStr
return obj.ToStr := val
sOpts := obj.ToStr
ret := Options_Opt(sOpts,name,val)
obj.ToStr := sOpts
return ret
}
Options_Import(obj,prm0){
options := obj
Loop, Parse, prm0, %A_Space%
{
if RegExMatch(A_LoopField,"wp(-[a-zA-Z0-9\s]*)",Match)
out .= "wp=" . Match1 . "¬"
, options.wp := Match1
else if RegExMatch(A_LoopField,"hp(-[a-zA-Z0-9\s]*)",Match)
out .= "hp=" . Match1 . "¬"
, options.hp := Match1
else if RegExMatch(A_LoopField,"wp(\+[a-zA-Z0-9\s]*)",Match)
out .= "wp=" . Match1 . "¬"
, options.wp := Match1
else if RegExMatch(A_LoopField,"hp(\+[a-zA-Z0-9\s]*)",Match)
out .= "hp=" . Match1 . "¬"
, options.hp := Match1
else if RegExMatch(A_LoopField,"xp(-[a-zA-Z0-9\s]*)",Match)
out .= "xp=" . Match1 . "¬"
, options.xp := Match1
else if RegExMatch(A_LoopField,"yp(-[a-zA-Z0-9\s]*)",Match)
out .= "yp=" . Match1 . "¬"
, options.yp := Match1
else if RegExMatch(A_LoopField,"xp(\+[a-zA-Z0-9\s]*)",Match)
out .= "xp=" . Match1 . "¬"
, options.xp := Match1
else if RegExMatch(A_LoopField,"yp(\+[a-zA-Z0-9\s]*)",Match)
out .= "yp=" . Match1 . "¬"
, options.yp := Match1
else if RegExMatch(A_LoopField,"xm(-[a-zA-Z0-9\s]*)",Match)
out .= "xm=" . Match1 . "¬"
, options.xm := Match1
else if RegExMatch(A_LoopField,"xm(\+[a-zA-Z0-9\s]*)",Match)
out .= "xm=" . Match1 . "¬"
, options.xm := Match1
else if RegExMatch(A_LoopField,"ym(-[a-zA-Z0-9\s]*)",Match)
out .= "ym=" . Match1 . "¬"
, options.ym := Match1
else if RegExMatch(A_LoopField,"ym(\+[a-zA-Z0-9\s]*)",Match)
out .= "ym=" . Match1 . "¬"
, options.ym := Match1
else if RegExMatch(A_LoopField,"xs(-[a-zA-Z0-9\s]*)",Match)
out .= "xs=" . Match1 . "¬"
, options.xs := Match1
else if RegExMatch(A_LoopField,"xs(\+[a-zA-Z0-9\s]*)",Match)
out .= "xs=" . Match1 . "¬"
, options.xs := Match1
else if RegExMatch(A_LoopField,"ys(-[a-zA-Z0-9\s]*)",Match)
out .= "ys=" . Match1 . "¬"
, options.ys := Match1
else if RegExMatch(A_LoopField,"ys(\+[a-zA-Z0-9\s]*)",Match)
out .= "ys=" . Match1 . "¬"
, options.ys := Match1
else if RegExMatch(A_LoopField,"ym",Match)
out .= "ym=True¬"
, options.ym := "True"
else if RegExMatch(A_LoopField,"xm",Match)
out .= "xm=True¬"
, options.xm := "True"
else if RegExMatch(A_LoopField,"xs",Match)
out .= "xs=True¬"
, options.xs := "True"
else if RegExMatch(A_LoopField,"ys",Match)
out .= "ys=True¬"
, options.ys := "True"
else if RegExMatch(A_LoopField,"v([a-zA-Z0-9\s]*)",Match){
Match1 = %Match1%
;MsgBox Var Imported
out .= "v" . "=" . Match1 . "¬"
options.Parent.v := Match1
obj.Parent[Match1] := options.Parent
}
else if RegExMatch(A_LoopField,"g([a-zA-Z0-9\s]*)",Match)
out .= "g" . "=" . Match1 . "¬"
, options.g := Match1
else if RegExMatch(A_LoopField,"w([a-zA-Z0-9\s]*)",Match)
out .= "w" . "=" . Match1 . "¬"
, options.w := Match1
else if RegExMatch(A_LoopField,"h([a-zA-Z0-9\s]*)",Match)
out .= "h" . "=" . Match1 . "¬"
, options.h := Match1
else if RegExMatch(A_LoopField,"x([a-zA-Z0-9\s]*)",Match)
out .= "x" . "=" . Match1 . "¬"
, options.x := Match1
else if RegExMatch(A_LoopField,"y([a-zA-Z0-9\s]*)",Match)
out .= "y" . "=" . Match1 . "¬"
, options.y := Match1
else if RegExMatch(A_LoopField,"\+([a-zA-Z0-9\s]*)",Match)
out .= Match1 . "=True¬"
, options[Match1] := "True"
else if RegExMatch(A_LoopField,"\-([a-zA-Z0-9\s]*)",Match)
out .= Match1 . "=False¬"
, options[Match1] := "False"
}
}
Options_ToParam(obj){
StringOpt := obj.ToStr
Loop, Parse, StringOpt, ¬
{
RegExMatch(A_LoopField,"([a-zA-Z0-9\s]*)=",name)
OptName = %name1%
RegExMatch(A_LoopField,"=(\+?-?[a-zA-Z0-9\s]*)",val)
OptVal = %val1%
if OptVal = False
RetVal .= "-" . OptName . " "
else if OptVal = True
RetVal .= "+" . OptName . " "
else
RetVal .= OptName . OptVal . " "
}
return RetVal
}
Options_SetParent(obj,parentObj){
}
Options(parent="",param="¬"){
static COBase
If !COBase
COBase := Object( "__Get" , "Options_GetVal" ; default getter
, "__Set" , "Options_SetVal" ; default setter
, "ToParam" , "Options_ToParam" ; .ToParam()
, "Import" , "Options_Import") ; .Import(sOptions)
; , "SetParent" , "Options_SetParent") ; .SetParent(parentObj)
obj := Object("ToStr", " ", "Parent"," ","base", COBase)
if (param != "¬"){
obj.Import(param)
}
return obj
}