WildByDesign Posted Saturday at 01:04 PM Author Posted Saturday at 01:04 PM @Nine Just a follow up on your new implementation: These is a brief white flicker occasionally. Not very often, but it would still be nice if we can avoid it. The flicker seems to only happen when hovering over the tabs (eg. hover back and forth over various tabs). I updated your example to include a check to ensure that the OS supports DarkMode_DarkTheme so that someone testing the script doesn't apply it on an incompatible OS. Regarding flicker. I added $WM_ERASEBKGND Then Return 1 to the subclass proc but it did not seem to help with the flicker in this case. Do you have any ideas to help reduce the flicker? expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x606060) GUISetFont(10, 300) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("") ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) If $iMsg = $WM_ERASEBKGND Then Return 1 ; ; Prevent background erase to avoid flicker If $iMsg <> $WM_PAINT Then Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) _WinAPI_CallWindowProc($pData, $hWnd, $iMsg, $wParam, $lParam) Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) ;_WinAPI_SelectObject($hDC, $hBrush) ;_WinAPI_ExtFloodFill($hDC, $tRect.right - 3, 3, _WinAPI_GetSysColor($COLOR_BTNFACE), $FLOODFILLSURFACE) Local $tRect2 = _GUICtrlTab_GetItemRectEx($hWnd, _GUICtrlTab_GetItemCount($hWnd) - 1) $tRect.left = $tRect2.right - 2 $tRect.bottom = $tRect2.bottom _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.left = 0 $tRect.right = 2 _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.bottom = 2 $tRect.right = $tRect2.right _WinAPI_FillRect($hDC, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hWnd, $hDC) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc
WildByDesign Posted Saturday at 01:45 PM Author Posted Saturday at 01:45 PM Although this is only supported on the very latest Windows 11 (24H2/25H2), this technique from @Nine is beautiful. You can even blend the colour in with the GUI background colour such as this: argumentum 1
Nine Posted Saturday at 02:06 PM Posted Saturday at 02:06 PM 58 minutes ago, WildByDesign said: Do you have any ideas to help reduce the flicker? I ran your code and no flicker. I hardly can help you with this as I do not see any on my side. Where do you see the flickers ? In the header or in the body ? “They did not know it was impossible, so they did it” ― Mark Twain 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 Interface Object based on Tag
WildByDesign Posted Saturday at 02:53 PM Author Posted Saturday at 02:53 PM (edited) 46 minutes ago, Nine said: Where do you see the flickers ? In the header or in the body ? The white flicker seems to be just the tiny strip above the two inactive tabs. Sometimes both inactive tabs get the white flicker if the two are side by side, but generally only one inactive tab gets the white flicker of the tiny strip just above it. Edited Saturday at 02:54 PM by WildByDesign
Nine Posted Saturday at 05:05 PM Posted Saturday at 05:05 PM 2 hours ago, WildByDesign said: The white flicker seems to be just the tiny strip above the two inactive tabs Yes I finally saw it. It happens quite rarely. I first tried with a back buffer ($hMemDC), but it doesn't work as the WM_PRINTCLIENT also catches the white line. But by using $WS_EX_COMPOSITED on the tab creation statement, I have not seen it thereafter. WildByDesign 1 “They did not know it was impossible, so they did it” ― Mark Twain 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 Interface Object based on Tag
WildByDesign Posted Saturday at 06:22 PM Author Posted Saturday at 06:22 PM 1 hour ago, Nine said: But by using $WS_EX_COMPOSITED on the tab creation statement, I have not seen it thereafter. That’s a nice idea. I didn’t know we could do that on the tab control itself. Thank you.
mLipok Posted Saturday at 10:09 PM Posted Saturday at 10:09 PM (edited) I think it would be usefull to add new wiki page about handling Thems and as example of course Dark Theme I mean to cumulate the knowledge how, why, when to use Themes. And how to do it well. Edited Saturday at 10:11 PM 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 Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
mLipok Posted yesterday at 03:13 AM Posted yesterday at 03:13 AM On 5/9/2026 at 3:04 PM, WildByDesign said: These is a brief white flicker occasionally The easiest way to trigger a blink is to click the middle TAB and then move LEFT <> RIGHT using the cursor keys on the keyboard. WildByDesign 1 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 Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
WildByDesign Posted yesterday at 10:05 AM Author Posted yesterday at 10:05 AM 6 hours ago, mLipok said: The easiest way to trigger a blink is to click the middle TAB and then move LEFT <> RIGHT using the cursor keys on the keyboard. Thank you. On 5/9/2026 at 1:05 PM, Nine said: But by using $WS_EX_COMPOSITED on the tab creation statement, I have not seen it thereafter. I did some more testing with this and put some more thought into it. The biggest problem is that as soon as you add a ListView to a tab, it causes an instant crash with WS_EX_COMPOSITED. So I don't think we can realistically use that, unfortunately. I really like WS_EX_COMPOSITED in general but it is not good with ListViews. I updated the example to include a ListView since I was testing that anyway with the composited ex style. But I added more tabs to bring about a more real world potential scenario. This also brings out the UpDown controls, so I have themed them as well. One problem at the moment is that the UpDown controls occasionally get painted over when you go to some of the tabs on the right side. We may need to use ExcludeClipRect to exclude the UpDown controls from being painted over if they exist. But I haven't looked that far into it yet. expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> #include <GuiListView.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) ;Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1, $WS_EX_COMPOSITED) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) ;GUICtrlCreateLabel("label2", 30, 80, 50, 20) Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 40, 60, 320, 200) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x202020) Local $hListView = GUICtrlGetHandle($idListview) Local $hHeader = _GUICtrlListView_GetHeader($idListView) Local $idLVi_Item1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview) Local $idLVi_Item2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview) Local $idLVi_Item3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview) GUICtrlCreateTabItem("tab3") GUICtrlCreateTabItem("tab4") GUICtrlCreateTabItem("tab5") GUICtrlCreateTabItem("tab6") GUICtrlCreateTabItem("") ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') ; set dark theme on ListView and header _WinAPI_SetWindowTheme($hListView, 'DarkMode_Explorer') If _is24H2Plus() Then _WinAPI_SetWindowTheme($hHeader, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) If $iMsg = $WM_ERASEBKGND Then Return 1 ; ; Prevent background erase to avoid flicker If $iMsg <> $WM_PAINT Then Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) _WinAPI_CallWindowProc($pData, $hWnd, $iMsg, $wParam, $lParam) Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) ;_WinAPI_SelectObject($hDC, $hBrush) ;_WinAPI_ExtFloodFill($hDC, 100, 100, 0xf9f9f9, $FLOODFILLSURFACE) ; light testing Local $tRect2 = _GUICtrlTab_GetItemRectEx($hWnd, _GUICtrlTab_GetItemCount($hWnd) - 1) $tRect.left = $tRect2.right - 2 $tRect.bottom = $tRect2.bottom _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.left = 0 $tRect.right = 2 _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.bottom = 2 $tRect.right = $tRect2.right _WinAPI_FillRect($hDC, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hWnd, $hDC) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx
WildByDesign Posted yesterday at 10:48 AM Author Posted yesterday at 10:48 AM (edited) This updated script excludes the UpDown control from being painted over: expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> #include <GuiListView.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) ;Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1, $WS_EX_COMPOSITED) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) ;GUICtrlCreateLabel("label2", 30, 80, 50, 20) Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 40, 60, 320, 200) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x202020) Local $hListView = GUICtrlGetHandle($idListview) Local $hHeader = _GUICtrlListView_GetHeader($idListView) Local $idLVi_Item1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview) Local $idLVi_Item2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview) Local $idLVi_Item3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview) GUICtrlCreateTabItem("tab3") GUICtrlCreateTabItem("tab4") GUICtrlCreateTabItem("tab5") GUICtrlCreateTabItem("tab6") GUICtrlCreateTabItem("") ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') ; set dark theme on ListView and header _WinAPI_SetWindowTheme($hListView, 'DarkMode_Explorer') If _is24H2Plus() Then _WinAPI_SetWindowTheme($hHeader, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) If $iMsg = $WM_ERASEBKGND Then Return 1 ; ; Prevent background erase to avoid flicker If $iMsg <> $WM_PAINT Then Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) _WinAPI_CallWindowProc($pData, $hWnd, $iMsg, $wParam, $lParam) Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) ;_WinAPI_SelectObject($hDC, $hBrush) ;_WinAPI_ExtFloodFill($hDC, 100, 100, 0xf9f9f9, $FLOODFILLSURFACE) ; light testing Local $tRect2 = _GUICtrlTab_GetItemRectEx($hWnd, _GUICtrlTab_GetItemCount($hWnd) - 1) $tRect.left = $tRect2.right - 2 $tRect.bottom = $tRect2.bottom ; exclude UpDown control from being painted over - ExcludeClipRect code from UEZ Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $iLeftCR, $iTopCR, $iRightCR, $iBottomCR Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then $tCR = _WinAPI_GetWindowRect($hTabUpDown) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or _ $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $iLeftCR = ($tCR.left > $tPR.left ? $tCR.left : $tPR.left) - $tPR.left $iTopCR = ($tCR.top > $tPR.top ? $tCR.top : $tPR.top) - $tPR.top $iRightCR = ($tCR.right < $tPR.right ? $tCR.right : $tPR.right) - $tPR.left $iBottomCR = ($tCR.bottom < $tPR.bottom ? $tCR.bottom : $tPR.bottom) - $tPR.top DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hDC, "int", $iLeftCR, "int", $iTopCR, "int", $iRightCR, "int", $iBottomCR) EndIf EndIf _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.left = 0 $tRect.right = 2 _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.bottom = 2 $tRect.right = $tRect2.right _WinAPI_FillRect($hDC, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hWnd, $hDC) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx Edited yesterday at 10:54 AM by WildByDesign
WildByDesign Posted yesterday at 01:26 PM Author Posted yesterday at 01:26 PM I've updated the script a bit more and removed the ListView because it didn't really serve any purpose in the example. I have also noticed that the flicker sometimes covers the entire tab item which does not make any sense because those tab items have a dark background to begin with because of the theming. So I'm perplexed as to how that more rare flicker occurs. The other areas of flicker is understandable because we are painting over white areas. @UEZ I apologize for tagging your directly, but I feel like we are onto something special here with the more modern tab control theme from Win11 24H2/25H2. It is more of a concept at the moment but quite nice. The problem that we are having is an occasional white flicker of the areas that are being painted over. It generally occurs if you hover the cursor over the inactive tabs back and forth for a bit. Without that flicker, this could potentially be a great solution. Adding $WS_EX_COMPOSITED to the tab control gets rid of the flicker very well. But of course, that would not be compatible with ListViews and it also seems to cause some weirdness with the UpDown control being visible. Without the UpDown control, it is perfect. But still not really an idea solution to the problem. Do you have any tricks for getting rid of that flicker? Here is my current testing script. Thank you. expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) ;Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1, $WS_EX_COMPOSITED) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab4") GUICtrlCreateTabItem("tab5") GUICtrlCreateTabItem("tab6") GUICtrlCreateTabItem("") ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) If $iMsg = $WM_ERASEBKGND Then Return 1 ; ; Prevent background erase to avoid flicker If $iMsg <> $WM_PAINT Then Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) _WinAPI_CallWindowProc($pData, $hWnd, $iMsg, $wParam, $lParam) Local $hDC = _WinAPI_GetWindowDC($hWnd) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) Local $tRect2 = _GUICtrlTab_GetItemRectEx($hWnd, _GUICtrlTab_GetItemCount($hWnd) - 1) $tRect.left = $tRect2.right - 2 $tRect.bottom = $tRect2.bottom ; exclude UpDown control from being painted over - ExcludeClipRect code from UEZ Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $iLeftCR, $iTopCR, $iRightCR, $iBottomCR Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then $tCR = _WinAPI_GetWindowRect($hTabUpDown) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or _ $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $iLeftCR = ($tCR.left > $tPR.left ? $tCR.left : $tPR.left) - $tPR.left $iTopCR = ($tCR.top > $tPR.top ? $tCR.top : $tPR.top) - $tPR.top $iRightCR = ($tCR.right < $tPR.right ? $tCR.right : $tPR.right) - $tPR.left $iBottomCR = ($tCR.bottom < $tPR.bottom ? $tCR.bottom : $tPR.bottom) - $tPR.top DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hDC, "int", $iLeftCR, "int", $iTopCR, "int", $iRightCR, "int", $iBottomCR) EndIf EndIf _WinAPI_FillRect($hDC, $tRect, $hBrush) ; paints area to the right of all tabs $tRect.left = 0 $tRect.right = 2 _WinAPI_FillRect($hDC, $tRect, $hBrush) ; paints area to the left of all tabs $tRect.bottom = 2 $tRect.right = $tRect2.right _WinAPI_FillRect($hDC, $tRect, $hBrush) ; paints strip on top of each tab _WinAPI_DeleteObject($hBrush) _WinAPI_ReleaseDC($hWnd, $hDC) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx
UEZ Posted yesterday at 05:16 PM Posted yesterday at 05:16 PM (edited) Took the code from my example and modified it: expandcollapse popup#include <WindowsNotifsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPITheme.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> #include <TabConstants.au3> #include <GuiTab.au3> ; Initialize System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Global $g_hTab_CB, $g_pTab_CB, $g_hProc, $g_hTab Global Const $COLOR_BUTTON_BG = 0x383838, $COLOR_BG_DARK = 0x202020, $COLOR_GUI_BG = 0x101010, $COLOR_BORDER = 0x606060, $COLOR_BORDER_DARK = 0x303030 Example() Func Example() Local $hGUI = GUICreate("DarkTheme TabControl (24H2/25H2)", 500, 300) GUISetBkColor($COLOR_GUI_BG) GUISetFont(10) Local $idTab = GUICtrlCreateTab(20, 20, 460, 260) $g_hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateTabItem("tab1") GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateTabItem("tab3") GUICtrlCreateTabItem("tab4") ; Remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) ; Set dark titlebar _WinAPI_DwmSetWindowAttribute($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True) ; Set theme if OS supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme(GUICtrlGetHandle($idTab), 'DarkMode_DarkTheme') ; Register Subclassing / Window Procedure $g_hTab_CB = DllCallbackRegister("_WinProc", "ptr", "hwnd;uint;wparam;lparam") $g_pTab_CB = DllCallbackGetPtr($g_hTab_CB) $g_hProc = _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_pTab_CB) GUISetState(@SW_SHOW) Local $idMsg While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd ; Cleanup: Restore original Window Procedure _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_hProc) DllCallbackFree($g_hTab_CB) EndFunc ;==>Example Func _is24H2Plus() ; Check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme." & @CRLF) EndIf Return $b24H2Plus EndFunc ;==>_is24H2Plus Func _WinProc($hWnd, $iMsg, $wParam, $lParam) ;coded by UEZ Switch $iMsg Case $WM_ERASEBKGND Return 1 ; Prevent background erasing to avoid flickering Case $WM_PAINT Local $tPaint = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint) If @error Or Not $hDC Then Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) Local $tClient = _WinAPI_GetClientRect($hWnd) Local $iWidth = $tClient.Right Local $iHeight = $tClient.Bottom ; Prepare Double Buffering Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap) ; --- 1. Clipping (Exclude child controls from drawing) --- Local $hParent = _WinAPI_GetParent($hWnd) Local $hChild = _WinAPI_GetWindow($hParent, $GW_CHILD) Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $left, $top, $right, $bottom While $hChild If $hChild <> $hWnd And _WinAPI_IsWindowVisible($hChild) Then $tCR = _WinAPI_GetWindowRect($hChild) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT) WEnd Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then $tCR = _WinAPI_GetWindowRect($hTabUpDown) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf ; 2. Draw main background (Dark color) Local $hBrushBg = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK)) ; _WinAPI_FillRect($hMemDC, $tClient, $hBrushBg) Local $iTabCount = _SendMessage($hWnd, $TCM_GETITEMCOUNT, 0, 0) Local $iCurSel = _SendMessage($hWnd, $TCM_GETCURSEL, 0, 0) ; 3. Prepare the Body Frame (The area beneath the tabs) Local $tFirstTabRect = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, 0, DllStructGetPtr($tFirstTabRect)) Local $tBodyRect = DllStructCreate($tagRECT) $tBodyRect.Left = 0 $tBodyRect.Top = $tFirstTabRect.Bottom ; Starts at the bottom edge of the tabs $tBodyRect.Right = $iWidth $tBodyRect.Bottom = $iHeight Local $hBrushBorder = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BORDER)) _WinAPI_FrameRect($hMemDC, $tBodyRect, $hBrushBorder) ; 4. Draw the "Gap" to the right of the tabs in GUI background color If $iTabCount > 0 Then Local $tLastTabRect = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, $iTabCount - 1, DllStructGetPtr($tLastTabRect)) Local $tGapRect = DllStructCreate($tagRECT) $tGapRect.Left = $tLastTabRect.Right + 2 $tGapRect.Top = 0 $tGapRect.Right = $iWidth $tGapRect.Bottom = $tLastTabRect.Bottom Local $hBrushGui = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_GUI_BG)) _WinAPI_FillRect($hMemDC, $tGapRect, $hBrushGui) _WinAPI_DeleteObject($hBrushGui) EndIf _WinAPI_SetBkMode($hMemDC, 1) ; Transparent background for text _WinAPI_SetTextColor($hMemDC, _ColorToCOLORREF(0xF0F0F0)) ; 5. Draw individual tabs For $i = 0 To $iTabCount - 1 Local $tRECT = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, $i, DllStructGetPtr($tRECT)) If $tRECT.Right < 0 Or $tRECT.Left > $iWidth Then ContinueLoop $tRECT.top -= 2 Local $bSelected = ($i = $iCurSel) Local $iTabColor = $bSelected ? $COLOR_BUTTON_BG : $COLOR_BG_DARK Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor)) ; Fill tab background _WinAPI_FillRect($hMemDC, $tRECT, $hTabBrush) If $bSelected Then ; Draw border ONLY for the active tab (Top, Left, Right) _WinAPI_FrameRect($hMemDC, $tRECT, $hBrushBorder) ; OPEN BOTTOM: Draw a line in tab-color over the body-border to merge them Local $tOpenLine = DllStructCreate($tagRECT) $tOpenLine.Left = $tRECT.Left + 1 $tOpenLine.Top = $tRECT.Bottom - 1 ; Exactly on the border line of the body $tOpenLine.Right = $tRECT.Right - 1 $tOpenLine.Bottom = $tRECT.Bottom + 1 _WinAPI_FillRect($hMemDC, $tOpenLine, $hTabBrush) Else ; Draw rectangle around non active tabs Local $hBrushTabRecDark = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BORDER_DARK)) _WinAPI_FrameRect($hMemDC, $tRECT, $hBrushTabRecDark) _WinAPI_DeleteObject($hBrushTabRecDark) EndIf _WinAPI_DeleteObject($hTabBrush) ; Draw text centered Local $sText = _GUICtrlTab_GetItemText($hWnd, $i) Local $tTextRect = DllStructCreate($tagRECT) With $tTextRect .Left = $tRECT.Left + 6 .Top = $tRECT.Top + ($bSelected ? 1 : 3) .Right = $tRECT.Right - 6 .Bottom = $tRECT.Bottom - 3 EndWith DllCall("user32.dll", "int", "DrawTextW", "handle", $hMemDC, "wstr", $sText, "int", -1, "struct*", $tTextRect, "uint", BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE, $DT_NOPREFIX)) Next ; 6. Copy memory DC to screen DC (BitBlt) _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY) ; Cleanup _WinAPI_SelectObject($hMemDC, $hOldBmp) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBrushBg) _WinAPI_DeleteObject($hBrushBorder) _WinAPI_DeleteDC($hMemDC) _WinAPI_EndPaint($hWnd, $tPaint) Return 0 EndSwitch Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Func _ColorToCOLORREF($iColor) ; Convert RGB to BGR Local $iR = BitAND(BitShift($iColor, 16), 0xFF) Local $iG = BitAND(BitShift($iColor, 8), 0xFF) Local $iB = BitAND($iColor, 0xFF) Return BitOR(BitShift($iB, -16), BitShift($iG, -8), $iR) EndFunc ;==>_ColorToCOLORREF Func Min($a, $b) Return ($a < $b ? $a : $b) EndFunc ;==>Min Func Max($a, $b) Return ($a > $b ? $a : $b) EndFunc ;==>Max Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx Does it help or do you insist of your test script? Edited yesterday at 07:55 PM by UEZ Extended the example WildByDesign and mLipok 1 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
WildByDesign Posted yesterday at 05:27 PM Author Posted yesterday at 05:27 PM 6 minutes ago, UEZ said: Does it help or do you insist of your test script? It works great, for sure. However, I am wondering if it can be done but avoid painting over the main tab content area? There are two reasons for this: - the main content area of tab is already dark with DarkMode_DarkTheme - the exclude rect for controls does not work well for all controls (eg. Group) So if we could just paint the tab items, this is my main goal for this experiment.
UEZ Posted yesterday at 05:33 PM Posted yesterday at 05:33 PM Here the modification of the test script: expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) ;Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1, $WS_EX_COMPOSITED) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab4") GUICtrlCreateTabItem("tab5") GUICtrlCreateTabItem("tab6") GUICtrlCreateTabItem("") ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) Switch $iMsg Case $WM_ERASEBKGND Return 1 ; Prevent background erase to avoid flicker Case $WM_PAINT Local $tPaint = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $iW = $tRect.Right Local $iH = $tRect.Bottom Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap) _SendMessage($hWnd, $WM_PRINTCLIENT, $hMemDC, 20) ; 20 = $PRF_CLIENT or $PRF_CHILDREN Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) Local $iTabCount = _GUICtrlTab_GetItemCount($hWnd) If $iTabCount > 0 Then Local $tRectLast = _GUICtrlTab_GetItemRectEx($hWnd, $iTabCount - 1) ; exclude UpDown control from being painted over - ExcludeClipRect code from UEZ Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then Local $tCR = _WinAPI_GetWindowRect($hTabUpDown) Local $tPR = _WinAPI_GetWindowRect($hWnd) DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hMemDC, _ "int", $tCR.Left - $tPR.Left, "int", $tCR.Top - $tPR.Top, _ "int", $tCR.Right - $tPR.Left, "int", $tCR.Bottom - $tPR.Top) EndIf ; paints area to the right of all tabs Local $tPatch = DllStructCreate($tagRECT) $tPatch.Left = $tRectLast.Right - 2 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = $tRectLast.Bottom _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints area to the left of all tabs $tPatch.Left = 0 $tPatch.Right = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints strip on top of each tab $tPatch.Left = 0 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) EndIf _WinAPI_DeleteObject($hBrush) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hOldBmp) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_EndPaint($hWnd, $tPaint) Return 0 EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx WildByDesign 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
WildByDesign Posted yesterday at 05:52 PM Author Posted yesterday at 05:52 PM 16 minutes ago, UEZ said: Here the modification of the test script: This is 100% perfect. Thank you! I think what I would like to do (in GUIDarkTheme UDF) is use this for users with 24H2/25H2 and use the one with full overpainting of tab content area with excluding of controls for Win10 and Win11 pre-24H2 users. This looks fantastic. Excellent work.
WildByDesign Posted yesterday at 06:06 PM Author Posted yesterday at 06:06 PM I am convinced that is the nicest looking tab control I have ever seen. 🤩
UEZ Posted yesterday at 08:02 PM Posted yesterday at 08:02 PM (edited) 13 hours ago, WildByDesign said: It works great, for sure. However, I am wondering if it can be done but avoid painting over the main tab content area? There are two reasons for this: - the main content area of tab is already dark with DarkMode_DarkTheme - the exclude rect for controls does not work well for all controls (eg. Group) So if we could just paint the tab items, this is my main goal for this experiment. I modified the example. I don't know if it fits now to your needs... Edited 17 hours ago by UEZ WildByDesign 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
WildByDesign Posted 13 hours ago Author Posted 13 hours ago (edited) 13 hours ago, UEZ said: I modified the example. I don't know if it fits now to your needs... I really like both examples. Both examples have a very beautiful dark mode design style. And it is fantastic to have choice. There is a problem that I am trying to figure out on both examples. Both examples have controls that disappear when going from tab to tab. From this example, I added labels with matching background color like this: GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $COLOR_BG_DARK) GUICtrlCreateTabItem("tab1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $COLOR_BG_DARK) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $COLOR_BG_DARK) GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $COLOR_BG_DARK) GUICtrlCreateTabItem("tab4") GUICtrlCreateLabel("label4", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $COLOR_BG_DARK) GUICtrlCreateTabItem("") ; end tabitem definition Even with ExcludeClipRect in this example, the controls are being lost. But they are not being overpainted which is interesting. For comparison, your SampleControls.au3 in Dark Mode example does not lose the controls even though it is the same technique from what I can tell. In the second example that does not use ExcludeClipRec, I added labels like this: GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlCreateTabItem("") ; end tabitem definition The labels generally show properly the majority of the time. But when you go back and forth on the tabs, once in a while the label will disappear. I tried with other controls and they also disappear. The first example is very easy to reproduce the disappearing controls. But on this second example, you probably have to switch tabs 20-30 times for each time a control disappears. EDIT: I figured out the problem with the first script. I just had to look at the difference between your SampleControls.au3 in Dark Mode: ; Exclude from offscreen bitmap (prevents black fill) DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) ; Exclude from screen DC (prevents BitBlt overwrite) DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hDC, "int", $left, "int", $top, "int", $right, "int", $bottom) This fixes it. Edited 13 hours ago by WildByDesign
WildByDesign Posted 11 hours ago Author Posted 11 hours ago (edited) 2 hours ago, WildByDesign said: The labels generally show properly the majority of the time. But when you go back and forth on the tabs, once in a while the label will disappear. I tried with other controls and they also disappear. The first example is very easy to reproduce the disappearing controls. But on this second example, you probably have to switch tabs 20-30 times for each time a control disappears. I was able to fix the second example as well where the controls were disappearing. The fix ended up being ExcludeClipRect on controls using technique from @UEZ But the interesting thing, to me at least, is that I did not think that we would need ExcludeClipRect on the controls because in this example we are not overpainting (FillRect) the main content area of the tab control. We are only overpainting the small areas on the tab items from my understanding. Regardless, ExcludeClipRect on the controls within the tab control is the fix for the disappearing controls. Here is my updated script of UEZ's second example: expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("Colored Tab", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab4") GUICtrlCreateLabel("label4", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab5") GUICtrlCreateLabel("label5", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab6") GUICtrlCreateLabel("label6", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("") ; end tabitem definition ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) Switch $iMsg Case $WM_ERASEBKGND Return 1 ; Prevent background erase to avoid flicker Case $WM_PAINT Local $tPaint = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $iW = $tRect.Right Local $iH = $tRect.Bottom Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap) _SendMessage($hWnd, $WM_PRINTCLIENT, $hMemDC, 20) ; 20 = $PRF_CLIENT or $PRF_CHILDREN Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) Local $iTabCount = _GUICtrlTab_GetItemCount($hWnd) If $iTabCount > 0 Then Local $tRectLast = _GUICtrlTab_GetItemRectEx($hWnd, $iTabCount - 1) ; Exclude overlapping GUI controls from painting Local $hParent = _WinAPI_GetParent($hWnd) Local $hChild = _WinAPI_GetWindow($hParent, $GW_CHILD) Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $left, $top, $right, $bottom ; Exclude overlapping GUI controls from painting While $hChild If $hChild <> $hWnd And _WinAPI_IsWindowVisible($hChild) Then $tCR = _WinAPI_GetWindowRect($hChild) ; Ensure control is within tab control If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or _ $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT) WEnd ; exclude UpDown control from being painted over - ExcludeClipRect code from UEZ Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then Local $tCR = _WinAPI_GetWindowRect($hTabUpDown) Local $tPR = _WinAPI_GetWindowRect($hWnd) DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hMemDC, _ "int", $tCR.Left - $tPR.Left, "int", $tCR.Top - $tPR.Top - 1, _ "int", $tCR.Right - $tPR.Left, "int", $tCR.Bottom - $tPR.Top + 2) DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hDC, _ "int", $tCR.Left - $tPR.Left, "int", $tCR.Top - $tPR.Top - 1, _ "int", $tCR.Right - $tPR.Left, "int", $tCR.Bottom - $tPR.Top + 2) EndIf ; paints area to the right of all tabs Local $tPatch = DllStructCreate($tagRECT) $tPatch.Left = $tRectLast.Right - 2 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = $tRectLast.Bottom _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints area to the left of all tabs $tPatch.Left = 0 $tPatch.Right = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints strip on top of each tab $tPatch.Left = 0 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) EndIf _WinAPI_DeleteObject($hBrush) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hOldBmp) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_EndPaint($hWnd, $tPaint) Return 0 EndSwitch Return __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx Func __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) Return DllCall('comctl32.dll', 'lresult', 'DefSubclassProc', 'hwnd', $hWnd, 'uint', $iMsg, 'wparam', $wParam, _ 'lparam', $lParam)[0] EndFunc ;==>__WinAPI_DefSubclassProc Func Min($a, $b) Return ($a < $b ? $a : $b) EndFunc ;==>Min Func Max($a, $b) Return ($a > $b ? $a : $b) EndFunc ;==>Max By the way, I added some more tabs to bring out the UpDown controls to theme those as well. There are some white artifacts showing on the UpDown buttons but I have not looked into that yet. EDIT: I made some minor adjustments to the UpDown control exclusion (ExcludeClipRect) and was able to fix the white artifacts that were showing above and below the UpDown buttons. Edited 11 hours ago by WildByDesign
WildByDesign Posted 10 hours ago Author Posted 10 hours ago @argumentum or anyone else who may admire dark mode tab controls: May I please get your opinion on this (below) as a modern tab control option for 24H2/25H2 users using DarkMode_DarkTheme? expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <GuiTab.au3> #include <WindowsSysColorConstants.au3> #include <WinAPITheme.au3> ; initiate System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Opt("MustDeclareVars", True) Example() Func Example() Local $hGUI = GUICreate("DarkTheme TabControl", 400, 300) GUISetBkColor(0x404040) GUISetFont(10, 300) Local $idTab = GUICtrlCreateTab(20, 20, 360, 260, -1) Local $hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateLabel("label2", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) Local $idAddTab = GUICtrlCreateButton("Trigger UpDown", 50, 120) _WinAPI_SetWindowTheme(GUICtrlGetHandle($idAddTab), 'DarkMode_Explorer') GUICtrlCreateTabItem("tab3") GUICtrlCreateLabel("label3", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("") ; end tabitem definition ; set DarkMode_DarkTheme visual theme on Tab control as long as OSBuild supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme($hTab, 'DarkMode_DarkTheme') ; get handle for UpDown control to apply theme Local $hUpDown = _WinAPI_FindWindowEx($hTab, "msctls_updown32") If _is24H2Plus() And $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, 'DarkMode_DarkTheme') Local $pAddress = _WinAPI_GetWindowLong($hTab, $GWL_WNDPROC) Local $hSubclass = DllCallbackRegister(WM_PAINT, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab, $pAddress) ; remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) ; needed to fix button frame when button is in tab control GUIRegisterMsg($WM_CTLCOLORBTN, "_WM_CTLCOLORBTN") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idAddTab _CreateNewTab() EndSwitch WEnd _WinAPI_RemoveWindowSubclass($hTab, DllCallbackGetPtr($hSubclass), $idTab) DllCallbackFree($hSubclass) EndFunc ;==>Example Func _CreateNewTab() GUICtrlCreateTabItem("tab4") GUICtrlCreateLabel("label4", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab5") GUICtrlCreateLabel("label5", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) GUICtrlCreateTabItem("tab6") GUICtrlCreateLabel("label6", 30, 80, 50, 20) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x262626) EndFunc Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) Switch $iMsg Case $WM_ERASEBKGND Return 1 ; Prevent background erase to avoid flicker Case $WM_PAINT Local $tPaint = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint) Local $tRect = _WinAPI_GetClientRect($hWnd) Local $iW = $tRect.Right Local $iH = $tRect.Bottom Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap) _SendMessage($hWnd, $WM_PRINTCLIENT, $hMemDC, 20) ; 20 = $PRF_CLIENT or $PRF_CHILDREN Local $hBrush = _WinAPI_CreateSolidBrush(0x404040) Local $iTabCount = _GUICtrlTab_GetItemCount($hWnd) If $iTabCount > 0 Then Local $tRectLast = _GUICtrlTab_GetItemRectEx($hWnd, $iTabCount - 1) ; Exclude overlapping GUI controls from painting Local $hParent = _WinAPI_GetParent($hWnd) Local $hChild = _WinAPI_GetWindow($hParent, $GW_CHILD) Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $left, $top, $right, $bottom ; Exclude overlapping GUI controls from painting While $hChild If $hChild <> $hWnd And _WinAPI_IsWindowVisible($hChild) Then $tCR = _WinAPI_GetWindowRect($hChild) ; Ensure control is within tab control If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or _ $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT) WEnd ; exclude UpDown control from being painted over - ExcludeClipRect code from UEZ Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then Local $tCR = _WinAPI_GetWindowRect($hTabUpDown) Local $tPR = _WinAPI_GetWindowRect($hWnd) DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hMemDC, _ "int", $tCR.Left - $tPR.Left, "int", $tCR.Top - $tPR.Top - 1, _ "int", $tCR.Right - $tPR.Left, "int", $tCR.Bottom - $tPR.Top + 2) DllCall('gdi32.dll', "int", "ExcludeClipRect", "handle", $hDC, _ "int", $tCR.Left - $tPR.Left, "int", $tCR.Top - $tPR.Top - 1, _ "int", $tCR.Right - $tPR.Left, "int", $tCR.Bottom - $tPR.Top + 2) EndIf ; paints area to the right of all tabs Local $tPatch = DllStructCreate($tagRECT) $tPatch.Left = $tRectLast.Right - 2 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = $tRectLast.Bottom _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints area to the left of all tabs $tPatch.Left = 0 $tPatch.Right = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) ; paints strip on top of each tab $tPatch.Left = 0 $tPatch.Top = 0 $tPatch.Right = $iW $tPatch.Bottom = 2 _WinAPI_FillRect($hMemDC, $tPatch, $hBrush) EndIf _WinAPI_DeleteObject($hBrush) _WinAPI_BitBlt($hDC, 0, 0, $iW, $iH, $hMemDC, 0, 0, $SRCCOPY) _WinAPI_SelectObject($hMemDC, $hOldBmp) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_EndPaint($hWnd, $tPaint) Return 0 Case $WM_PARENTNOTIFY ; Fired when a child window is created inside the tab control. ; The tab spinner (msctls_updown32) is created lazily by Windows when tabs overflow - ; it doesn't exist at init time, so we theme it here the moment it appears. If _WinAPI_LoWord($wParam) = $WM_CREATE Then Local $hNewChild = HWnd($lParam) ; lParam carries the new child's HWND as integer - must cast! If _WinAPI_GetClassName($hNewChild) = "msctls_updown32" Then If _is24H2Plus() Then _WinAPI_SetWindowTheme($hNewChild, 'DarkMode_DarkTheme') EndIf EndIf Return __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndSwitch Return __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_PAINT Func _is24H2Plus() ; check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme.") EndIf Return $b24H2Plus EndFunc Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall('user32.dll', "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx Func __WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) Return DllCall('comctl32.dll', 'lresult', 'DefSubclassProc', 'hwnd', $hWnd, 'uint', $iMsg, 'wparam', $wParam, _ 'lparam', $lParam)[0] EndFunc ;==>__WinAPI_DefSubclassProc Func Min($a, $b) Return ($a < $b ? $a : $b) EndFunc ;==>Min Func Max($a, $b) Return ($a > $b ? $a : $b) EndFunc ;==>Max Func _WM_CTLCOLORBTN($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hCtrl = $lParam Local $hBrush = _WinAPI_CreateSolidBrush(0x262626) Return $hBrush EndFunc ;==>_CTLCOLORBTN I am considering adding it to GUIDarkTheme UDF specifically for 24H2/25H2 users as a modern tab control option. Windows 10 and Windows 11 (pre-24H2/25H2) would still have the fully drawn tab control.
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