See comment "Only process the statusbar"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <WinAPI.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 192, 124)
GUICtrlSetDefColor(0x000000)
GUICtrlSetDefBkColor(0xFF0000)
$hStatus = _GUICtrlStatusBar_Create($Form1)
GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
_GUICtrlStatusBar_SetText($hStatus, "test", 0, $SBT_OWNERDRAW)
Global $global_StatusBar_Text = "Part 1"
$Button1 = GUICtrlCreateButton("Button1", 176, 136, 75, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
; $d = _FileListToArrayRec(@ScriptDir & "\ico", "*.ico", 0, 1, 0, 1)
For $x = 1 To 100
; ConsoleWrite($d[$x] & @CRLF)
Sleep(20)
$global_StatusBar_Text = $x
_WinAPI_RedrawWindow($hStatus)
; _GUICtrlStatusBar_SetText($hStatus, $x & " " & $x, 0, $SBT_OWNERDRAW)
Next
EndSwitch
WEnd
Func _WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
#forceref $Msg, $wParam, $lParam
Local $tDRAWITEMSTRUCT = DllStructCreate("uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;HWND hwndItem;HANDLE hDC;long rcItem[4];ULONG_PTR itemData", $lParam)
If DllStructGetData($tDRAWITEMSTRUCT, "hwndItem") <> $hStatus Then Return $GUI_RUNDEFMSG ; Only process the statusbar
Local $itemID = DllStructGetData($tDRAWITEMSTRUCT, "itemID") ;part number
Local $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC")
Local $tRect = DllStructCreate("long left;long top;long right; long bottom", DllStructGetPtr($tDRAWITEMSTRUCT, "rcItem"))
Local $iTop = DllStructGetData($tRect, "top")
Local $iLeft = DllStructGetData($tRect, "left")
Local $hBrush
Switch $itemID
Case 0
$hBrush = _WinAPI_CreateSolidBrush(0x0000FF) ; Backgound Color
_WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrush)
_WinAPI_SetTextColor($hDC, 0x00FF00) ; Font Color
_WinAPI_SetBkMode($hDC, $TRANSPARENT)
DllStructSetData($tRect, "top", $iTop + 1)
DllStructSetData($tRect, "left", $iLeft + 1)
_WinAPI_DrawText($hDC, $global_StatusBar_Text, $tRect, $DT_LEFT)
_WinAPI_DeleteObject($hBrush)
EndSwitch
$tDRAWITEMSTRUCT = 0
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_DRAWITEM