#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <MenuConstants.au3>
#include <WindowsConstants.au3>
Global Enum $i_CGB_BttnCnt, $i_CGB_BttnID, $i_CGB_hWin, $i_CGB_Total
Global $aGCB_Data[1][1]
$hGUI = GUICreate('GUICaptionButton', 300, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP))
GUISetState(@SW_SHOW, $hGUI)
$iClose_Bttn = _GUICaptionButton_Create($hGUI, $SC_CLOSE)
$iMax_Bttn = _GUICaptionButton_Create($hGUI, $SC_MAXIMIZE, $GUI_DISABLE)
$iMin_Bttn = _GUICaptionButton_Create($hGUI, $SC_MINIMIZE)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $iClose_Bttn
Exit
Case $iMax_Bttn
Case $iMin_Bttn
GUISetState(@SW_MINIMIZE, $hGUI)
EndSwitch
WEnd
Func _GUICaptionButton_Create($hWnd, $iButton, $iState = -1)
Local $aWinPos, $aWinClntSize, $iCaption_Height, $iW, $iH, $iL, $iT, $hGUI, $iBttn
Static $SC_BTTN_COUNT = -1
$SC_BTTN_COUNT += 1
$aWinPos = WinGetPos($hWnd)
$aWinClntSize = WinGetClientSize($hWnd)
$iCaption_Height = $aWinPos[3] - $aWinClntSize[1]
$iW = 20
$iH = $iCaption_Height - 7
$iL = ($aWinPos[0] + $aWinPos[2]) - $iW - 5 - (($iW + 3) * $SC_BTTN_COUNT)
$iT = $aWinPos[1]
$hGUI = GUICreate('', $iW, $iH, $iL, $iT, $WS_POPUP, $WS_EX_TOPMOST, $hWnd)
Switch $iButton
Case $SC_CLOSE
$iBttn = GUICtrlCreateButton('x', 0, 0, $iW, $iH, $BS_ICON)
GUICtrlSetImage(-1, 'imageres.dll', -219, 0)
GUICtrlSetFont(-1, 8.5, 800, 0, 'Wingdings')
Case $SC_MINIMIZE
$iBttn = GUICtrlCreateButton('', 0, 0, $iW, $iH)
GUICtrlSetFont(-1, 8.5, 800, 0, 'Webdings')
Case $SC_MAXIMIZE
$iBttn = GUICtrlCreateButton('c', 0, 0, $iW, $iH)
GUICtrlSetFont(-1, 8.5, 800, 0, 'Webdings')
Case $SC_CONTEXTHELP
$iBttn = GUICtrlCreateButton('?', 0, 0, $iW, $iH)
EndSwitch
GUICtrlSetState($iBttn, $iState)
GUISetState(@SW_SHOWNOACTIVATE, $hGUI)
If $SC_BTTN_COUNT = 0 Then
GUIRegisterMsg($WM_WINDOWPOSCHANGED, '__GCB_WM_WINDOWPOS')
;GUIRegisterMsg($WM_ACTIVATE, '__GCB_WM_WINDOWPOS')
EndIf
ReDim $aGCB_Data[$SC_BTTN_COUNT + 2][$i_CGB_Total]
$aGCB_Data[0][0] = $hWnd
$aGCB_Data[$SC_BTTN_COUNT + 1][$i_CGB_BttnCnt] = $SC_BTTN_COUNT
$aGCB_Data[$SC_BTTN_COUNT + 1][$i_CGB_BttnID] = $iBttn
$aGCB_Data[$SC_BTTN_COUNT + 1][$i_CGB_hWin] = $hGUI
Return $iBttn
EndFunc
Func __GCB_WM_WINDOWPOS($hWnd, $iMsg, $wParam, $lParam)
If $aGCB_Data[0][0] <> $hWnd Or Not BitAND(WinGetState($hWnd), 8) Then
Return $GUI_RUNDEFMSG
EndIf
Local $aWinPos, $aWinClntSize, $iCaption_Height, $iW, $iH, $iL, $iT
$aWinPos = WinGetPos($hWnd)
$aWinClntSize = WinGetClientSize($hWnd)
$iCaption_Height = $aWinPos[3] - $aWinClntSize[1]
For $i = 1 To UBound($aGCB_Data)-1
$iW = 20
$iH = $iCaption_Height - 7
$iL = ($aWinPos[0] + $aWinPos[2]) - $iW - 5 - (($iW + 3) * $aGCB_Data[$i][$i_CGB_BttnCnt])
$iT = $aWinPos[1]
WinMove($aGCB_Data[$i][$i_CGB_hWin], '', $iL, $iT)
Next
Return $GUI_RUNDEFMSG
EndFunc