Jump to content

Recommended Posts

Posted

haha..... I do not see this issue in this example :)

#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsNotifsConstants.au3>
#include <WindowsSysColorConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.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")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateTabItem("tab2")
    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
        WinMove($hGUI, "", 400, 300, (8 * Random(0, 1, 1)) + 157)
        Sleep(400)
        $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_RED))
            _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_DARKSLATEGRAY : $COLOR_BG_DARK
                Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor))

                ; Fill tab background
                _WinAPI_FillRect($hMemDC, $tRECT, $hTabBrush)

                If $bSelected Then
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_VIOLET))
                    ; 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
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_RED))
                    ; 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

 

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"
:naughty:  :ranting:, 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

Posted
10 minutes ago, mLipok said:

hey you know what ?
I have an idea: Try to focus on how the "frame" is drawn here

Interesting. Do you mean draw the blue as part of the frame (non-client area) instead of the pen?

Or do you mean get the rect measurements from the frame?

Posted
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsNotifsConstants.au3>
#include <WindowsSysColorConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.au3>
#include <WindowsConstants.au3>

; Initialize System DPI awareness
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2)

Global $hGUI, $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()
    $hGUI = GUICreate("ESC to exit - DarkTheme TabControl (24H2/25H2)", 500, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP))

    GUISetBkColor($COLOR_GUI_BG)
    GUISetFont(10)

    Local $idTab = GUICtrlCreateTab(20, 20, 460, 260)
    GUICtrlSetResizing(-1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
    $g_hTab = GUICtrlGetHandle($idTab)

    GUICtrlCreateTabItem("tab0")
    GUICtrlCreateTabItem("tab1")
    GUICtrlSetState(-1, $GUI_SHOW)
    GUICtrlCreateTabItem("tab2")
    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)

    AdlibRegister(OhBabyYouMoveMyWindow_song, 500)

    While 1
        If GUIGetMsg() = $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 OhBabyYouMoveMyWindow_song()
    WinMove($hGUI, "", @DesktopWidth / 2, @DesktopHeight / 2, (8 * Random(40, 80, 1)))
EndFunc

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_RED))
            _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_DARKSLATEGRAY : $COLOR_BG_DARK
                Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor))

                ; Fill tab background
                _WinAPI_FillRect($hMemDC, $tRECT, $hTabBrush)

                If $bSelected Then
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_VIOLET))
                    ; 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
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_RED))
                    ; 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

I'm not sure what's going on, but I think this is a better example. 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting  image.gif.922e3a93535f431de08b31ee669cc446.gif
autoit_scripter_blue_userbar.png

Posted
1 hour ago, WildByDesign said:

Interesting. Do you mean draw the blue as part of the frame (non-client area) instead of the pen?

Or do you mean get the rect measurements from the frame?

Not sure what exactly you mean, as I said I not following this thread from begining and Im not expert here.

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"
:naughty:  :ranting:, 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

Posted
1 hour ago, mLipok said:

Not sure what exactly you mean, as I said I not following this thread from begining and Im not expert here.

Sorry, that was my fault for causing confusion. I had misunderstood your suggestion initially since I couldn’t test the code earlier.

I think everything is OK now because that bug is so difficult to reproduce and it doesn’t seem to occur in the SampleControls demo either.

Posted

Did you have oportunity to test my 2 last examples?

Any comment on them ?

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"
:naughty:  :ranting:, 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

Posted
1 hour ago, mLipok said:

Did you have oportunity to test my 2 last examples?

Any comment on them ?

First of all, I just wanted to thank you for helped throughout the day. I appreciate your time.

You did a great job of reproducing the issue in the one script. It was such a difficult issue to reproduce because it had to be very precise. And you nailed it.

I like the script where your paint that red line around in a very similar design style. We could certainly use that to match the design. I think that the only thing that it lacks is the hover color change when hovering over each inactive tab. I will have to see if we can do that. Likely something to do with $TCIS_HIGHLIGHTED

Posted
6 minutes ago, WildByDesign said:

I think that the only thing that it lacks is the hover color change when hovering over each inactive tab. I will have to see if we can do that. Likely something to do with $TCIS_HIGHLIGHTED

check: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-nmmouse

but.. I have also other idea... working on

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"
:naughty:  :ranting:, 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

Posted (edited)

  

1 hour ago, WildByDesign said:

I think that the only thing that it lacks is the hover color change when hovering over each inactive tab. I will have to see if we can do that. Likely something to do with $TCIS_HIGHLIGHTED

32 minutes ago, mLipok said:

I have also other idea... working on

 

Please check the following example focusing on #Region ; Fill tab background

#Region ; *** Dynamically added Include files ***
#include <Array.au3>                                         ; added:05/16/26 00:23:43
#EndRegion ; *** Dynamically added Include files ***
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WindowsNotifsConstants.au3>
#include <WindowsSysColorConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.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_RED))
            _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

                #Region ; Fill tab background
                Local $aWinPos = WinGetPos($hWnd)
                Local $aMousePos = MouseGetPos()
                ConsoleWrite("$aWinPos : " & _ArrayToString($aWinPos) & @CRLF)
                ConsoleWrite("$aMousePos : " & _ArrayToString($aMousePos) & @CRLF)
                ConsoleWrite("HitTest : " & _ArrayToString(_GUICtrlTab_HitTest($hWnd, $aMousePos[0] - $aWinPos[0], $aMousePos[1] - $aWinPos[1])) & @CRLF)
                Local $bMouseOverTab = (_GUICtrlTab_HitTest($hWnd, $aMousePos[0] - $aWinPos[0], $aMousePos[1] - $aWinPos[1])[0] > -1)
                Local $bSelected = ($i = $iCurSel)
                Local $iTabColor = ($bSelected Or $bMouseOverTab) ? $COLOR_DARKSLATEGRAY : $COLOR_BG_DARK
                Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor))
                _WinAPI_FillRect($hMemDC, $tRECT, $hTabBrush)
                #EndRegion ; Fill tab background

                If $bSelected Then
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_VIOLET))
                    ; Draw border ONLY for the active tab (Top, Left, Right)
                    _WinAPI_FrameRect($hMemDC, $tRECT, $hBrushBorder)

                    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
                    ; OPEN BOTTOM: Draw a line in tab-color over the body-border to merge them
                    _WinAPI_FillRect($hMemDC, $tOpenLine, $hTabBrush)
                Else
                    _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_RED))
                    ; 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

 

btw.
there are some issues but it is a good start

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 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"
:naughty:  :ranting:, 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

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
×
×
  • Create New...