Jump to content

Recommended Posts

Posted (edited)

Is there any way to SetBKColor for one selected part in StatusBar ?

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I made a quick example

#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(0xFFFF00)
            _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), $hBrush)
            _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

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Posted

Thank You very much

It is exactly what I need

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...