Toggle Button

Homepage: A Better Bitmap Button Class

ToggleBtnHWND := DllCall("AHKCtrlSupport\CreateToggleBtnID", Str, "BtnText", DWORD, dwexStyle, DWORD, Button2HWnd, int, toggle, int, up, int, down, int, disabled, int, fill, "Cdecl Int")


ToggleBtnHWND NULL if there was an error
The handle to the control. You must store this HWND to access the Dllcall of AdjustToggleBtn to set the properties of the newly created button
Str "BtnText" Specifies the text to display on the button
dwexStyle See GUI styles in the AHK-help
Button2HWnd The HWND to the existing button which should be replaced. Use Button2HWnd := GetChildHWND(HWND, "Button2") to retrieve the handle
toggle Should the button toggle? That means that the button stays pressed after clicking it.



nRC := DllCall("AHKCtrlSupport\AdjustToggleBtn", int, ToggleBtnHWND, int, 0x300, int, 0x400, int, 118, int, 123, int, 0, int, 0, "Cdecl Int")


nRC returnvalue: 0 = error
1 = ok
ToggleBtnHWND Handle to the button from CreateToggleBtnID
horizontal Style BS_LEFT=0x100: Show icon on the left side
BS_CENTER=0x300: Show icon centered
BS_RIGHT=0x200: Show icon on the right side
verical Style BS_TOP=0x400: Show icon on the top
BS_VCENTER=0xC00: Show icon vertically centered
BS_BOTTOM=0x800: Show icon on the bottom
up ID of the icon-resource of the resourcedll (shown when the button is not pressed)
down ID of the icon-resource of the resourcedll (shown when the button is pressed)
disabled The button is disabled
fill Resizes the bitmap to fit the button



Example:

; --------------- Create a Toggle Button ---------------------------
; -----------------------------------------------------------------------
dwexStyle := 0x40000000 | 0x10000000 | 0x00010000 | 0x0000000B | 0x00004000 | 0x0300
toggle = true
up = true
disabled = false
fill = true
ToggleBtnHWND := DllCall("AHKCtrlSupport\CreateToggleBtnID", Str, "BtnText", DWORD, dwexStyle, DWORD, Button2HWnd, int, toggle, int, up, int, down, int, disabled, int, fill, "Cdecl Int")
if (errorlevel <> 0) || (nRC = 0)
{
	MsgBox error while calling CreateToggleBtnID Errorlevel: %errorlevel% - RC: %nRC%
	return
}
;BS_LEFT = 0x100, BS_RIGHT = 0x200, BS_CENTER = 0x300, BS_TOP = 0x400, BS_BOTTOM = 0x800, BS_VCENTER = 0xC00,
; Parameter: HWND, Left/center/right, top/center/bottom, iconID1, iconID2
nRC := DllCall("AHKCtrlSupport\AdjustToggleBtn", int, ToggleBtnHWND, int, 0x300, int, 0x400, int, 118, int, 123, int, 0, int, 0, "Cdecl Int")
if (errorlevel <> 0) || (nRC = 0)
{
	MsgBox error while calling AdjustToggleBtn Errorlevel: %errorlevel% - RC: %nRC%
	return
}