Jump to content

Changing the tab color

Recommended Posts

Hi, i wish if everybody is having a good day ...
is there any way to change the color of the tab that in the pic below ?


Share this post

Link to post
Share on other sites

Unfortunately you require a workaround to get it to work, a nice workaround from Yashied post below
nb: Since AutoIt has updated since Yashied posted this, I have added the latest includes in the code below. 

#Include <Constants.au3>
#Include <GUITab.au3>
#include <WinAPI.au3>
#include <WinAPITheme.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
Opt('MustDeclareVars', 1)

Global Const $PRF_CLIENT = 0x04

Global $hTab, $hDll, $pDll, $hProc

GUICreate('MyGUI', 300, 300)
GUICtrlCreateTab(20, 20, 262, 261, $TCS_FOCUSONBUTTONDOWN)
$hTab = GUICtrlGetHandle(-1)
GUICtrlCreateTabItem('Tab 1')
GUICtrlCreateTabItem('Tab 2')
GUICtrlCreateTabItem('Tab 3')

$hDll = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
$pDll = DllCallbackGetPtr($hDll)
$hProc = _WinAPI_SetWindowLong($hTab, $GWL_WNDPROC, $pDll)



Until GUIGetMsg() = -3

Func _CreateClipRgn($hWnd)

    Local $tRect
    Local $Count = _GUICtrlTab_GetItemCount($hWnd)
    Local $Sel = _GUICtrlTab_GetCurSel($hWnd)
    Local $hRgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)
    Local $hTmp, $Ht

    For $i = 0 To $Count - 1
        $tRect = _GUICtrlTab_GetItemRectEx($hWnd, $i)
        If $i = $Sel Then
            $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1) - 2, DllStructGetData($tRect, 2) - 2, DllStructGetData($tRect, 3) + 2, DllStructGetData($tRect, 4))
            $Ht = DllStructGetData($tRect, 4) - DllStructGetData($tRect, 2) + 2
            If $i = $Count - 1 Then
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - 2, DllStructGetData($tRect, 4))
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3), DllStructGetData($tRect, 4))
        _WinAPI_CombineRgn($hRgn, $hRgn, $hTmp, $RGN_OR)
    $tRect = _WinAPI_GetClientRect($hWnd)
    $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2) + $Ht, DllStructGetData($tRect, 3) - 2, DllStructGetData($tRect, 4) - 1)
    _WinAPI_CombineRgn($hRgn, $hRgn, $hTmp, $RGN_OR)
    Return $hRgn
EndFunc   ;==>_CreateClipRgn

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    If _WinAPI_IsThemeActive() Then
        Switch $iMsg
            Case $WM_ERASEBKGND
                Local $hRgn = _CreateClipRgn($hWnd)
                Local $hPrev = _WinAPI_GetClipRgn($wParam)
                Local $hBrush = _WinAPI_CreateSolidBrush(0xFFCCAA)
                Local $tRect = _WinAPI_GetClientRect($hWnd)
                _WinAPI_ExtSelectClipRgn($wParam, $hRgn, $RGN_DIFF)
                _WinAPI_FillRect($wParam, DllStructGetPtr($tRect), $hBrush)
                _WinAPI_SelectClipRgn($wParam, $hPrev)
                Return 1
            Case $WM_PAINT
                Local $tPaint
                Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint)
                Local $hRgn = _CreateClipRgn($hWnd)
                _WinAPI_ExtSelectClipRgn($hDC, $hRgn, $RGN_AND)
                _WinAPI_CallWindowProc($hProc, $hWnd, $WM_PRINTCLIENT, $hDC, $PRF_CLIENT)
                _WinAPI_EndPaint($hWnd, $tPaint)
                Return 0
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func AutoItExit()
    _WinAPI_SetWindowLong($hTab, $GWL_WNDPROC, $hProc)
EndFunc   ;==>AutoItExit


Share this post

Link to post
Share on other sites

So, it seems _GUICtrlTab_SetBkColor() is no longer a thing. And Autoit updates have effected the original postings of Yashied's workaround and Melba23's solutions but I don't know enough about WinAPI to fiddle them into working. Subz helpful update here works on my system but addresses a very specific request and only changes the color of the space at the top of the tab by the tab names. And since this thread is somewhat recent, I thought I'd just ask here instead of posting a new one.

What is the current workaround to change to entire tab color? I'm not fond of the white...


Share this post

Link to post
Share on other sites

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