I've created an AHK v2 version of my control zoo. Hopefully this will provide some useful template code for anyone who wants to get started with GUIs in AHK v2.
control zoo (AHK v1.1) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=30652
Code: Select all
;AHK v2 script (tested on AHK v2.0-a081-cad307c)
;'control zoo (ahk v2).ahk' by jeeswg
#SingleInstance force
vInput := 111
vInput := InputBox("show built-in controls 1/show built-in controls 2/show custom controls",,, vInput)
vShowBuiltIn1 := SubStr(vInput, 1, 1)
vShowBuiltIn2 := SubStr(vInput, 2, 1)
vShowCustom := SubStr(vInput, 3, 1)
;==================================================
;GUI Control Types
;https://autohotkey.com/docs/commands/GuiControls.htm
;•Text, Edit, UpDown, Picture
;•Button, Checkbox, Radio
;•DropDownList, ComboBox
;•ListBox, ListView, TreeView
;•Link, Hotkey, DateTime, MonthCal
;•Slider, Progress
;•GroupBox, Tab, StatusBar
;•ActiveX (e.g. Internet Explorer Control)
;•Custom
;tabbed = in vShowBuiltIn1 (11 control types + DDL = 12)
;Text [Static]
;Edit [Edit]
;UpDown [msctls_updown32]
;Picture [Static]
;Button [Button]
;Checkbox [Button]
;Radio [Button]
;DropDownList [ComboBox]
;ComboBox [ComboBox + Edit]
;ListBox [ListBox]
;ListView [SysListView32 + SysHeader32]
;TreeView [SysTreeView32]
;Link [SysLink]
;Hotkey [msctls_hotkey32]
;DateTime [SysDateTimePick32]
;MonthCal [SysMonthCal32]
;Slider [msctls_trackbar32]
;Progress [msctls_progress32]
;GroupBox [Button]
;Tab [SysTabControl32]
;StatusBar [msctls_statusbar32]
;ActiveX (e.g. Internet Explorer Control) [AtlAxWin + Shell Embedding + Shell DocObject View + Internet Explorer_Server]
;Custom []
;[RICHEDIT50W]
;[Scintilla]
;[ToolbarWindow32]
;==================================================
;create window
DetectHiddenWindows("On")
oGui := GuiCreate(, "control zoo")
oGui.OnEvent("Close", "Gui_Close")
hGui := oGui.hWnd
OnMessage(0x111, "WM_COMMAND")
;==================================================
;menu
if vShowBuiltIn1
{
Menu("SubMenu1", "Add")
Menu("SubMenu2", "Add")
Menu("SubMenu3", "Add")
Menu("SubMenu1", "DeleteAll")
Menu("SubMenu2", "DeleteAll")
Menu("SubMenu3", "DeleteAll")
Menu("MenuBar", "Add", "MENU 1", ":SubMenu1")
Menu("MenuBar", "Add", "MENU 2", ":SubMenu2")
Menu("MenuBar", "Add", "MENU 3", ":SubMenu3")
Menu("SubMenu1", "Add", "MENU 1.1", "MyMenuLabel")
Menu("SubMenu1", "Add", "MENU 1.2", "MyMenuLabel")
Menu("SubMenu1", "Add", "MENU 1.3", "MyMenuLabel")
Menu("SubMenu2", "Add", "MENU 2.1", "MyMenuLabel")
Menu("SubMenu2", "Add", "MENU 2.2", "MyMenuLabel")
Menu("SubMenu2", "Add", "MENU 2.3", "MyMenuLabel")
Menu("SubMenu3", "Add", "MENU 3.1", "MyMenuLabel")
Menu("SubMenu3", "Add", "MENU 3.2", "MyMenuLabel")
Menu("SubMenu3", "Add", "MENU 3.3", "MyMenuLabel")
oGui.Menu := "MenuBar"
}
;==================================================
;built-in control types
if vShowBuiltIn1
{
vPos := vShowCustom ? "y30" : "" ;make room for toolbar if needed
oGui.Add("Text", vPos, "STATIC 1")
oGui.Add("Edit",, "EDIT 1")
oBtn := oGui.Add("Button",, "BTN 1")
oBtn.OnEvent("Click", Func("MyButtonFunc").bind(oBtn))
oGui.Add("DropDownList",, "CBX 'DDL' 1||CBX 'DDL' 2|CBX 'DDL' 3")
oGui.Add("ComboBox",, "CBX 1||CBX 2|CBX 3")
oGui.Add("ListBox", "+Multi", "LBX 1||LBX 2|LBX 3") ;LBS_EXTENDEDSEL := 0x800 ;LBS_MULTIPLESEL := 0x8
oLV := oGui.Add("ListView", "r3", "LVH 1|LVH 2|LVH 3")
;oLV := oGui.Add("ListView", "+Grid r3", "LVH 1|LVH 2|LVH 3")
Loop 3
if (A_Index = 1)
oLV.Add("Select", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
else
oLV.Add("", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
oTV := oGui.Add("TreeView")
vTV1 := oTV.Add("TV 1", "", "Select")
vTV2 := oTV.Add("TV 2", vTV1)
vTV3 := oTV.Add("TV 3", vTV2)
vTV4 := oTV.Add("TV 4", vTV1)
vTV5 := oTV.Add("TV 5")
oGui.Add("Link",, "<a href=`"https://autohotkey.com/`">https://autohotkey.com/</a>")
oGui.Add("DateTime", "Choose20060504030201", "HH:mm:ss dd/MM/yyyy")
oSB := oGui.Add("StatusBar",, "SB 1")
oSB.SetParts(50, 50, 50)
oSB.SetText("SB 2", 2)
oSB.SetText("SB 3", 3)
oWB := oGui.Add("ActiveX", "w240 h100", "Shell.Explorer").Value
oWB.Navigate("https://www.google.com/")
;OLECMDID_OPTICAL_ZOOM := 63 ;OLECMDEXECOPT_DONTPROMPTUSER := 2
while oWB.busy || !(oWB.ReadyState = 4)
Sleep(100)
oWB.ExecWB(63, 2, 30, 0) ;zoom 30%
oWB.document.parentWindow.scrollBy(120, 35)
}
;==================================================
;built-in control types further
if vShowBuiltIn2
{
vPosX := (vShowBuiltIn1 && vShowBuiltIn2) ? "x300" : "" ;shift to right, if all controls being shown
vPosY := (!vShowBuiltIn1 && vShowCustom) ? "y30" : "" ;make room for toolbar if needed
vPosY := (vShowBuiltIn1 && vShowBuiltIn2 && vShowCustom) ? "y30" : vPosY ;make room for toolbar if needed
oGui.Add("Edit", vPosX " " vPosY) ;for UpDown
oGui.Add("UpDown",, 100)
oGui.Add("Picture",, A_AhkPath)
oGui.Add("Checkbox", "Checked", "BTN 2")
oGui.Add("Radio", "Checked", "BTN 3")
oGui.Add("Radio",, "BTN 4")
oGui.Add("Radio", "Checked Group", "BTN 5")
oGui.Add("Radio",, "BTN 6")
oGui.Add("GroupBox", "h20", "BTN 7")
oGui.Add("Hotkey",, "^q")
oGui.Add("MonthCal",, "20060504030201")
oGui.Add("Slider", "h30", 100)
oGui.Add("Progress", "+Smooth", 100) ;PBS_SMOOTH := 0x1
;oGui.Add("Progress", "+0x1", 100) ;PBS_SMOOTH := 0x1
oGui.Add("Progress",, 50)
oGui.Add("Progress",, 100)
oTab := oGui.Add("Tab3", "h40", "TAB 1|TAB 2|TAB 3")
oTab.UseTab() ;future controls are not part of any tab control
}
;==================================================
;custom control types
if vShowCustom
{
;RICHEDIT50W
hModuleME := DllCall("kernel32\LoadLibrary", Str,"msftedit.dll", Ptr)
vPos := (!vShowBuiltIn1 && !vShowBuiltIn2) ? "y30" : "" ;make room for toolbar if needed
oGui.Add("Custom", vPos " ClassRICHEDIT50W r1")
ControlSetText("RICH 1", "RICHEDIT50W1", "ahk_id " hGui)
;Scintilla
;Download Scintilla and SciTE
;http://www.scintilla.org/SciTEDownload.html
;Scintilla controls: SciLexer.dll x64/x32 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=5&t=41663
vSfx := (A_PtrSize = 8) ? 64 : 32
if FileExist(vPathSciLexer := A_ScriptDir "\SciLexer" vSfx ".dll")
|| FileExist(vPathSciLexer := RegExReplace(A_AhkPath, "\\[^\\]*$") "\SciLexer" vSfx ".dll")
{
hModuleSL := DllCall("kernel32\LoadLibrary", Str,vPathSciLexer, Ptr)
oGui.Add("Custom", "ClassScintilla r2")
;ControlSetText("SCIN 1", "Scintilla1", "ahk_id " hGui) ;only shows 'S'
ControlSend("SCIN 1", "Scintilla1", "ahk_id " hGui)
;SC_CP_UTF8 := 65001
SendMessage(2037, 65001,, "Scintilla1", "ahk_id " hGui) ;SCI_SETCODEPAGE := 2037
}
;ToolbarWindow32
;oGui.Add("Custom", "ClassToolbarWindow32")
oGui.Add("Custom", "ClassToolbarWindow32 0x100") ;TBSTYLE_TOOLTIPS := 0x100
;oGui.Add("Custom", "ClassToolbarWindow32 0x1000") ;TBSTYLE_LIST := 0x1000 ;text to side of buttons
;oGui.Add("Custom", "ClassToolbarWindow32 0x1100")
hTB := ControlGetHwnd("ToolbarWindow321", "ahk_id " hGUI)
SendMessage(0x43C, 0, 0,, "ahk_id " hTB) ;TB_SETMAXTEXTROWS := 0x43C ;text omitted from buttons
;note: if more than one button has the same idCommand, then only the last button with that idCommand will have a ToolTip
vCount := 5, vSize := A_PtrSize=8?32:20
VarSetCapacity(TBBUTTON, vCount*vSize, 0)
Loop vCount
{
vText%A_Index% := "TB " A_Index
vOffset := (A_Index-1)*vSize
;TBSTATE_ENABLED := 4
NumPut(A_Index-1, &TBBUTTON, vOffset, "Int") ;iBitmap
NumPut(A_Index-1, &TBBUTTON, vOffset+4, "Int") ;idCommand
NumPut(0x4, &TBBUTTON, vOffset+8, "UChar") ;fsState
NumPut(&vText%A_Index%, &TBBUTTON, vOffset+(A_PtrSize=8?24:16), "Ptr") ;iString
}
hIL := IL_Create(5, 2, 0)
IL_Add(hIL, A_AhkPath, -159) ;green H
IL_Add(hIL, A_AhkPath, -206) ;green S
IL_Add(hIL, A_AhkPath, -207) ;red H
IL_Add(hIL, A_AhkPath, -208) ;red S
IL_Add(hIL, A_AhkPath, -160) ;file icon
SendMessage(0x430, 0, hIL,, "ahk_id " hTB) ;TB_SETIMAGELIST := 0x430
vMsg := A_IsUnicode?0x444:0x414
SendMessage(vMsg, vCount, &TBBUTTON,, "ahk_id " hTB) ;TB_ADDBUTTONSW := 0x444 ;TB_ADDBUTTONSA := 0x414
}
;==================================================
;default width is 266
if vShowBuiltIn1 && vShowBuiltIn2
oGui.Show("w600")
else
oGui.Show()
if hTB
SendMessage(0x421,,,, "ahk_id " hTB) ;TB_AUTOSIZE := 0x421
;ControlMove(0, 0, 0, 0,, "ahk_id " hTB)
return
;==================================================
MyMenuLabel:
ToolTip(0)
Sleep(1500)
ToolTip()
return
MyButtonFunc(oCtl)
{
ToolTip(oCtl.Text)
Sleep(1500)
ToolTip()
}
Gui_Close()
{
ExitApp()
}
;==================================================
WM_COMMAND(wParam, lParam, uMsg, hWnd)
{
DetectHiddenWindows("On")
vWinClass := WinGetClass("ahk_id " lParam)
if (vWinClass = "ToolbarWindow32")
{
ToolTip(wParam)
Sleep(1500)
ToolTip()
}
}
;==================================================