Jump to content

Get color of a Solid Brush


Bilgus
 Share

Recommended Posts

Shamelessly ripped from Raymond @ TheNewOldThing

get the color of a SOLID brush

#include <WinAPIGdi.au3> ;CreateSolidBrush
#include <WinAPIHObj.au3>

Local $hBrush = _WinAPI_CreateSolidBrush(0xFFDEDEFF)

ConsoleWrite("Brush Color = 0x" & Hex(_GetBrushColor($hBrush)) & @CRLF)

_WinAPI_DeleteObject($hBrush)


Func _GetBrushColor($hBrush)
    ;https://devblogs.microsoft.com/oldnewthing/20190802-00/?p=102747
    Local $iErr
    Local Const $BS_SOLID = 0x00000000
    Local Const $tagLogBrush = "uint lbStyle; dword lbColor; ulong_ptr lbHatch"
    Local $tLogBrush = DllStructCreate($tagLogBrush)
    Local $iSzLogBrush = DllStructGetSize($tLogBrush)
    If _WinAPI_GetObject($hBrush, $iSzLogBrush, DllStructGetPtr($tLogBrush)) <> $iSzLogBrush Then
        $iErr = 0x1
    ElseIf DllStructGetData($tLogBrush, "lbStyle") <> $BS_SOLID Then
        $iErr = 0x2
    Else
        Return DllStructGetData($tLogBrush, "lbColor")
    EndIf
    Return SetError($iErr, 0, 0xFFFFFFFF) ;CLR_NONE
EndFunc

 

Link to comment
Share on other sites

Func GUIStaticCtrlGetBkColor($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hWnd_Main = _WinAPI_GetParent ($hWnd)
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hBrush = _SendMessage($hWnd_Main, $WM_CTLCOLORSTATIC, $hdc, $hWnd)
    Local $iColor = _GetBrushColor($hBrush)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return $iColor
EndFunc

Here is @guinness'  GUICtrlGetBkColor converted to use GetBrushColor()

Edited by Bilgus
Link to comment
Share on other sites

  • 3 months later...

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
 Share

  • Recently Browsing   0 members

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