#include <GUIConstantsEX.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
Opt('MustDeclareVars', 1)
Global $hFont
Global $aParts[3] = [125, 250]
Global $aPartsText[2] = ["RED on Transparent", "BLUE on Transparent"]
Global $hGUI = GUICreate("statusbar custom font and colour demo", 400, 300)
GUISetBkColor(0xE0FFFF)
Global $hStatus = _GUICtrlStatusBar_Create($hGUI)
_GUICtrlStatusBar_SetParts($hStatus, $aParts)
Global $tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000)
Global $tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0)
_GUICtrlStatusBar_SetText($hStatus, "Not ownerdrawn", 2)
_GUICtrlStatusBar_SetFont($hStatus, 16, 800, 0, "Comic Sans MS")
GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
GUISetState()
$tPart0 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[0], 0, 0xFF0000)
$tPart1 = _GUICtrlStatusBar_SetColor($hStatus, $aPartsText[1], 1, 0x0C0DC0)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
_WinAPI_DeleteObject($hFont)
Func _GUICtrlStatusBar_SetFont($hWnd, $iHeight = 15, $iWeight = 400, $iFontAtrributes = 0, $sFontName = "Arial")
$hFont = _WinAPI_CreateFont($iHeight, 0, 0, 0, $iWeight, BitAND($iFontAtrributes, 2), BitAND($iFontAtrributes, 4), _
BitAND($iFontAtrributes, 8), $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, _
$DEFAULT_QUALITY, 0, $sFontName)
_SendMessage($hWnd, $WM_SetFONT, $hFont, 1)
EndFunc ;==>_GUICtrlStatusBar_SetFont
Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Local $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;" & _
"uint itmAction;uint itmState;hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam)
Local $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm"); retrieve statusbar handle
Switch _WinAPI_GetClassName($hItm)
Case "msctls_statusbar32"
Local $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
Local $iID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
Local $pParam = DllStructGetData($tagDRAWITEMSTRUCT, "itmData")
Local $tParam = DllStructCreate("wchar[512];dword;dword;dword", $pParam)
Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom")
DllStructSetData($tRECT, "Left", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1) + 1)
DllStructSetData($tRECT, "Top", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 2) + 1)
DllStructSetData($tRECT, "Right", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 3))
DllStructSetData($tRECT, "Bottom", DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 4))
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
_WinAPI_SetTextColor($hDC, DllStructGetData($tParam, 2))
If Not DllStructGetData($tParam, 4) Then
Local $iBkColor = DllStructGetData($tParam, 3), $hStatusDC, $hBrushBk
$hStatusDC = _WinAPI_GetDC($hItm)
$hBrushBk = _WinAPI_CreateSolidBrush($iBkColor)
_WinAPI_FillRect($hStatusDC, DllStructGetPtr($tRECT), $hBrushBk)
_WinAPI_DeleteObject($hBrushBk)
_WinAPI_ReleaseDC($hItm, $hStatusDC)
EndIf
_WinAPI_DrawText($hDC, DllStructGetData($tParam, 1), $tRECT, $DT_LEFT)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_DRAWITEM
Func _GUICtrlStatusBar_SetColor($hWnd, $sText = "", $iPart = 0, $iColor = 0, $iBkColor = -1)
Local $ret, $tStruct, $pStruct, $iBuffer
$tStruct = DllStructCreate("wchar Text[512];dword Color;dword BkColor;dword Trans")
Switch $iBkColor
Case -1
DllStructSetData($tStruct, "Trans", 1)
Case Else
$iBkColor = BitAND(BitShift(String(Binary($iBkColor)), 8), 0xFFFFFF)
DllStructSetData($tStruct, "Trans", 0)
DllStructSetData($tStruct, "BkColor", $iBkColor)
EndSwitch
$iColor = BitAND(BitShift(String(Binary($iColor)), 8), 0xFFFFFF)
DllStructSetData($tStruct, "Text", $sText)
DllStructSetData($tStruct, "Color", $iColor)
$pStruct = DllStructGetPtr($tStruct)
If _GUICtrlStatusBar_IsSimple($hWnd) Then $iPart = $SB_SIMPLEID
If _WinAPI_InProcess($hWnd, $__ghSBLastWnd) Then
$ret = _SendMessage($hWnd, $SB_SetTEXTW, BitOR($iPart, $SBT_OWNERDRAW), $pStruct, 0, "wparam", "ptr")
Return $tStruct
EndIf
Return 0
EndFunc ;==>_GUICtrlStatusBar_SetColor