Sign in to follow this  
Followers 0
rootx

[SOLVED] _WinAPI_SetWindowTheme color text status bar?

11 posts in this topic

#2 ·  Posted (edited)

Any advice is welcome. THX.

Edited by rootx

Share this post


Link to post
Share on other sites

Any advice is welcome. THX.

Share this post


Link to post
Share on other sites

Based on this excellent example by funkey...

#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $hGUI, $hStatus
Global $aParts[3] = [75, 150, -1]

$hGUI = GUICreate("StatusBar Set BkColor", 400, 300)
GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")
$hStatus = _GUICtrlStatusBar_Create($hGUI)
GUISetState()

;~ _GUICtrlStatusBar_SetBkColor($hStatus, 0x5555DD)

_GUICtrlStatusBar_SetParts($hStatus, $aParts)
_GUICtrlStatusBar_SetText($hStatus, "Part 1", 0, $SBT_OWNERDRAW)
_GUICtrlStatusBar_SetText($hStatus, "Part 2", 1, $SBT_OWNERDRAW)
_GUICtrlStatusBar_SetText($hStatus, "Part 3", 2, $SBT_OWNERDRAW)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

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)
    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, "Part 1", $tRect, $DT_LEFT)
            _WinAPI_DeleteObject($hBrush)

        Case 1
            $hBrush = _WinAPI_CreateSolidBrush(0x00FF00)
            _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrush)
            _WinAPI_SetBkMode($hDC, $TRANSPARENT)
            DllStructSetData($tRect, "top", $iTop + 1)
            DllStructSetData($tRect, "left", $iLeft + 1)
            _WinAPI_DrawText($hDC, "Part 2", $tRect, $DT_LEFT)
            _WinAPI_DeleteObject($hBrush)

        Case 2
            $hBrush = _WinAPI_CreateSolidBrush(0xABCDEF)
            _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrush)
            _WinAPI_SetBkMode($hDC, $TRANSPARENT)
            DllStructSetData($tRect, "top", $iTop + 1)
            DllStructSetData($tRect, "left", $iLeft + 1)
            _WinAPI_DrawText($hDC, "Part 3", $tRect, $DT_LEFT)
            _WinAPI_DeleteObject($hBrush)

    EndSwitch

    $tDRAWITEMSTRUCT = 0
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_DRAWITEM

 

1 person likes this

Share this post


Link to post
Share on other sites

Thx, but I'm not sure how to implement it on my script, I populate the stausbar with a loop..

#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)
$hStatus = _GUICtrlStatusBar_Create($Form1)
GUIRegisterMsg($WM_DRAWITEM, "_WM_DRAWITEM")

_GUICtrlStatusBar_SetText($hStatus,"test",0,$SBT_OWNERDRAW)

$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 UBound($d) -1
                ConsoleWrite($d[$x]&@CRLF)
                _GUICtrlStatusBar_SetText($hStatus,$x&"  "&$d[$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)
    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, "Part 1", $tRect, $DT_LEFT)
            _WinAPI_DeleteObject($hBrush)
    EndSwitch

    $tDRAWITEMSTRUCT = 0
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_DRAWITEM

 

Share this post


Link to post
Share on other sites
#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)
$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)
    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

 

1 person likes this

Share this post


Link to post
Share on other sites

!!!!!! what a fool I am, THX 4your Time, THX again.

Share this post


Link to post
Share on other sites

One more question please, how can I prevent this border??

 

#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)
    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

 

test.JPG

Share this post


Link to post
Share on other sites

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

 

1 person likes this

Share this post


Link to post
Share on other sites

Thx 4 the explanation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0