#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
Global Const $SM_CXFIXEDFRAME = 7 ;Window border size
$nCaption_Color = _SwitchColor_RGB_BGR(_WinAPI_GetSysColor($COLOR_ACTIVECAPTION))
$iCaption_Height = _WinAPI_GetSystemMetrics($SM_CYCAPTION)
$iBorder_Size = _WinAPI_GetSystemMetrics($SM_CXFIXEDFRAME)
$hGUI = GUICreate(" Custom Caption button", 350, 200)
$hButton_GUI = GUICreate("", 25, $iCaption_Height - $iBorder_Size, -1, -1, $WS_POPUP, $WS_EX_LAYERED, $hGUI)
GUISetBkColor($nCaption_Color)
$nStick_Button = GUICtrlCreateCheckbox("л", 0, 0, 25, $iCaption_Height - $iBorder_Size, BitOr($GUI_SS_DEFAULT_CHECKBOX, $BS_PUSHLIKE), $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 14, 200, 0, "Webdings")
GUICtrlSetTip(-1, "Stick window (Set OnTop)")
_WinAPI_SetLayeredWindowAttributes($hButton_GUI, $nCaption_Color, 0, $LWA_COLORKEY)
GUIRegisterMsg($WM_MOVE, "WM_MOVE")
_GUIButtonSetPos_Proc()
GUISetState(@SW_SHOW, $hButton_GUI)
GUISetState(@SW_SHOW, $hGUI)
AdlibRegister("_CheckButtonState", 10)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _CheckButtonState()
Local $aCurInfo = GUIGetCursorInfo($hButton_GUI)
If IsArray($aCurInfo) And $aCurInfo[2] = 1 And $aCurInfo[4] = $nStick_Button Then
WinSetOnTop($hGUI, "", GUICtrlRead($nStick_Button) <> $GUI_CHECKED)
ElseIf WinActive($hButton_GUI) Then
WinActivate($hGUI)
EndIf
EndFunc
Func _GUIButtonSetPos_Proc()
Local $aGUIPos = WinGetPos($hGUI)
Local $iX = $aGUIPos[0]
Local $iY = $aGUIPos[1]
WinMove($hButton_GUI, "", $iX + 30, $iY + $iBorder_Size + ($iBorder_Size / 2))
EndFunc
Func WM_MOVE($hWndGUI, $iMsg, $wParam, $lParam)
;Local $iX = BitAND($lParam, 0xFFF)
;Local $iY = BitShift($lParam, 16)
_GUIButtonSetPos_Proc()
EndFunc
Func _SwitchColor_RGB_BGR($iColor)
Local $iMask = BitXOR(BitAND($iColor, 0xFF), ($iColor / 0x10000))
Return "0x" & Hex(BitXOR($iColor, ($iMask * 0x10001)), 6)
EndFunc