control zoo (AHK v1.1)
Posted: 16 Apr 2017, 17:58
I have been writing some functions which I hope to post soon, that get/set the text for various control types, for internal controls that belong to the AHK exe and for external controls.
I created this 'control zoo' for testing purposes, but it is quite entertaining to look at, and is quite useful for explaining how to create GUI controls in AutoHotkey including toolbars.
[EDIT: slightly improved script]
See also:
GUIs via DllCall: control zoo - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32106
I created this 'control zoo' for testing purposes, but it is quite entertaining to look at, and is quite useful for explaining how to create GUI controls in AutoHotkey including toolbars.
[EDIT: slightly improved script]
Code: Select all
;AHK v1.1 script
;'control zoo (ahk v1.1).ahk' by jeeswg
#SingleInstance force
;vInput := 101
InputBox, vInput,, show built-in controls 1/show built-in controls 2/show custom controls,,,,,,,, 101
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
Gui, New, +HwndhGui, control zoo
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
Gui, Menu, MenuBar
}
;==================================================
;built-in control types
if vShowBuiltIn1
{
vPos := vShowCustom ? "y30" : "" ;make room for toolbar if needed
Gui, Add, Text, % vPos, STATIC 1
Gui, Add, Edit,, EDIT 1
Gui, Add, Button, gMyButtonLabel, BTN 1
Gui, Add, DropDownList,, CBX 'DDL' 1||CBX 'DDL' 2|CBX 'DDL' 3
Gui, Add, ComboBox,, CBX 1||CBX 2|CBX 3
Gui, Add, ListBox, +Multi, LBX 1||LBX 2|LBX 3 ;LBS_EXTENDEDSEL := 0x800 ;LBS_MULTIPLESEL := 0x8
Gui, Add, ListView, r3, LVH 1|LVH 2|LVH 3
;Gui, Add, ListView, +Grid r3, LVH 1|LVH 2|LVH 3
Loop, 3
if (A_Index = 1)
LV_Add("Select", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
else
LV_Add("", "LV A" A_Index, "LV B" A_Index, "LV C" A_Index)
Gui, Add, TreeView
vTV1 := TV_Add("TV 1", "", "Select")
vTV2 := TV_Add("TV 2", vTV1)
vTV3 := TV_Add("TV 3", vTV2)
vTV4 := TV_Add("TV 4", vTV1)
vTV5 := TV_Add("TV 5")
Gui, Add, Link,, <a href="https://autohotkey.com/">https://autohotkey.com/</a>
Gui, Add, DateTime, Choose20060504030201, HH:mm:ss dd/MM/yyyy
Gui, Add, StatusBar,, SB 1
SB_SetParts(50, 50, 50)
SB_SetText("SB 2", 2)
SB_SetText("SB 3", 3)
Gui, Add, ActiveX, w240 h100 voWB, Shell.Explorer
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
{
vPos := (!vShowBuiltIn1 && vShowCustom) ? "y30" : "" ;make room for toolbar if needed
Gui, Add, Edit, % vPos ;for UpDown
Gui, Add, UpDown,, 100
Gui, Add, Picture,, % A_AhkPath
Gui, Add, Checkbox, Checked, BTN 2
Gui, Add, Radio, Checked, BTN 3
Gui, Add, Radio,, BTN 4
Gui, Add, Radio, Checked Group, BTN 5
Gui, Add, Radio,, BTN 6
Gui, Add, Hotkey,, ^q
Gui, Add, MonthCal,, 20060504030201
Gui, Add, Slider,, 100
Gui, Add, Progress,, 100
Gui, Add, Progress, -0x1, 50 ;PBS_SMOOTH := 0x1
Gui, Add, Progress, -Smooth, 100 ;PBS_SMOOTH := 0x1
Gui, Add, GroupBox,, BTN 7
Gui, Add, Tab3, h40, TAB 1|TAB 2|TAB 3
Gui, Tab ;future controls are not part of any tab control
}
;==================================================
;custom control types
if vShowCustom
{
;RICHEDIT50W
hModuleME := DllCall("kernel32.dll\LoadLibrary", Str,"msftedit.dll", Ptr)
vPos := (!vShowBuiltIn1 && !vShowBuiltIn2) ? "y30" : "" ;make room for toolbar if needed
Gui, Add, Custom, % vPos " ClassRICHEDIT50W r1"
ControlSetText, RICHEDIT50W1, % "RICH 1", % "ahk_id " hGui
;Scintilla
;Download Scintilla and SciTE
;http://www.scintilla.org/SciTEDownload.html
if FileExist(vPathSciLexer := A_ScriptDir "\SciLexer.dll")
{
hModuleSL := DllCall("kernel32.dll\LoadLibrary", Str,vPathSciLexer, Ptr)
Gui, Add, Custom, ClassScintilla r2
;ControlSetText, Scintilla1, SCIN 1, % "ahk_id " hGui ;only shows 'S'
ControlSend, Scintilla1, SCIN 1, % "ahk_id " hGui
;SCI_SETCODEPAGE := 2037 ;SC_CP_UTF8 := 65001
SendMessage, 2037, 65001,, Scintilla1, % "ahk_id " hGui ;SCI_SETCODEPAGE
}
;ToolbarWindow32
;Gui, Add, Custom, ClassToolbarWindow32
Gui, Add, Custom, ClassToolbarWindow32 0x100 ;TBSTYLE_TOOLTIPS := 0x100
;Gui, Add, Custom, ClassToolbarWindow32 0x1000 ;TBSTYLE_LIST := 0x1000 ;text to side of buttons
;Gui, Add, Custom, ClassToolbarWindow32 0x1100
ControlGet, hTB, Hwnd,, ToolbarWindow321, % "ahk_id " hGUI
SendMessage, 0x43C, 0, 0,, % "ahk_id " hTB ;TB_SETMAXTEXTROWS ;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
;TB_ADDBUTTONSW := 0x444 ;TB_ADDBUTTONSA := 0x414
vMsg := A_IsUnicode?0x444:0x414
SendMessage, % vMsg, % vCount, % &TBBUTTON,, % "ahk_id " hTB ;TB_ADDBUTTONSW / TB_ADDBUTTONSA
}
;==================================================
Gui, Show
if hTB
SendMessage, 0x421,,,, % "ahk_id " hTB ;TB_AUTOSIZE
;ControlMove,, 0, 0, 0, 0, % "ahk_id " hTB
return
;==================================================
MyMenuLabel:
MyButtonLabel:
ToolTip, 0
Sleep 1500
ToolTip
return
;==================================================
WM_COMMAND(wParam, lParam, uMsg, hWnd)
{
DetectHiddenWindows, On
WinGetClass, vWinClass, % "ahk_id " lParam
if (vWinClass = "ToolbarWindow32")
{
ToolTip, % wParam
Sleep 1500
ToolTip
}
}
;==================================================
GUIs via DllCall: control zoo - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32106