AutoXenon Posted November 20, 2022 Posted November 20, 2022 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.
Nine Posted November 20, 2022 Posted November 20, 2022 Have you tried _WinAPI_GetBkColor ? “They did not know it was impossible, so they did it” ― Mark Twain Want some cheese with your whine ? Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
AutoXenon Posted November 21, 2022 Author Posted November 21, 2022 (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 November 21, 2022 by AutoXenon
KaFu Posted November 21, 2022 Posted November 21, 2022 $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) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
AutoXenon Posted November 21, 2022 Author Posted November 21, 2022 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
Nine Posted November 21, 2022 Posted November 21, 2022 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 “They did not know it was impossible, so they did it” ― Mark Twain Want some cheese with your whine ? Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now