Jump to content

Recommended Posts

Posted

There had been like 5 threads in the past ten years talking about how it's a hassle to set the tab control background color.

Yet the seemingly simple reverse -- getting the tab background color and matching everything else to it -- is not talked about at all.

How do you retrieve the default background color of tab controls used by the current operating system?

Windows 10 is rgb(255,255,255), and Windows 11 seems to be some weird shade of pinkish white that is not found in any registry entries, so no luck there either.

Posted (edited)

That's for device contexts, we do not know if the color being drawn as the tab background is the same as the gdi device context.

 

GUISetBkColor(0x00ff00,GUICreate(''))
Local $tabs = GUICtrlCreateTab(10,10,380,380)
Local $tab1 = GUICtrlCreateTabItem('test')
GUICtrlCreateTabItem('')
GUISetState()

local $bkColor = DllCall('gdi32.dll','dword','GetBkColor','handle',DllCall('user32.dll','hwnd','GetDC','hwnd',$tabs)[0])[0]
      $bkColor = BitShift(BitAnd(0x000000FF,$bkColor),-16) + BitAnd(0x0000FF00,$bkColor) + BitShift(BitAnd(0x00FF0000,$bkColor),16)
msgbox(0,'Tabs BkColor',Hex($bkColor)) ; clearly incorrect

local $bkColor = DllCall('gdi32.dll','dword','GetBkColor','handle',DllCall('user32.dll','hwnd','GetDC','hwnd',$tab1)[0])[0]
      $bkColor = BitShift(BitAnd(0x000000FF,$bkColor),-16) + BitAnd(0x0000FF00,$bkColor) + BitShift(BitAnd(0x00FF0000,$bkColor),16)
msgbox(0,'Tab1 BkColor',Hex($bkColor)) ; can't tell when I'm not on Win11

 

Edited by AutoXenon
Posted

$tabs is a control ID, not a handle.

GUISetBkColor(0x00ff00, GUICreate(''))
Local $tabs = GUICtrlCreateTab(10, 10, 380, 380)
Local $tab1 = GUICtrlCreateTabItem('test')
GUICtrlCreateTabItem('')
GUISetState()

#include <WinAPIGdiDC.au3>
#include <WinAPIGdi.au3>

$hWnd_tabs = GUICtrlGetHandle($tabs)
$hDC_tabs = _WinAPI_GetDC($hWnd_tabs)
MsgBox(0,"","0x" & hex(_WinAPI_GetBkColor($hDC_tabs)))
_WinAPI_ReleaseDC($hWnd_tabs, $hDC_tabs)

$hWnd_tabs = GUICtrlGetHandle($tab1)
$hDC_tabs = _WinAPI_GetDC($hWnd_tabs)
MsgBox(0,"","0x" & hex(_WinAPI_GetBkColor($hDC_tabs)))
_WinAPI_ReleaseDC($hWnd_tabs, $hDC_tabs)

 

Posted

Thanks but clearly it is still not giving the actual background color, only the default canvas color of the DC. Your version still returns 0x00ffffff, when the actual background of $tabs is 0x00f0f0f0

Posted

I do not have Win11, but this should work :

#include <GUIConstants.au3>
#include <WinAPIGdi.au3>

GUISetBkColor(0x00ff00, GUICreate(''))
Local $tabs = GUICtrlCreateTab(10, 10, 380, 380)
Local $tab1 = GUICtrlCreateTabItem('test')
GUICtrlCreateTabItem('')
GUISetState()

$hWnd_tabs = GUICtrlGetHandle($tabs)
$hDC_tabs = _WinAPI_GetDC($hWnd_tabs)
ConsoleWrite("0x" & hex(_WinAPI_GetPixel($hDC_tabs, 1, 1)) & @CRLF)
_WinAPI_ReleaseDC($hWnd_tabs, $hDC_tabs)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

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...