Jump to content

Changing the tab color


Recommended Posts

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)
GUISetBkColor(0xAACCFF)
GUICtrlCreateTab(20, 20, 262, 261, $TCS_FOCUSONBUTTONDOWN)
$hTab = GUICtrlGetHandle(-1)
GUICtrlCreateTabItem('Tab 1')
GUICtrlCreateTabItem('Tab 2')
GUICtrlCreateTabItem('Tab 3')
GUICtrlCreateTabItem('')

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

OnAutoItExitRegister('AutoItExit')

GUISetState()

Do
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
        Else
            If $i = $Count - 1 Then
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3) - 2, DllStructGetData($tRect, 4))
            Else
                $hTmp = _WinAPI_CreateRectRgn(DllStructGetData($tRect, 1), DllStructGetData($tRect, 2), DllStructGetData($tRect, 3), DllStructGetData($tRect, 4))
            EndIf
        EndIf
        _WinAPI_CombineRgn($hRgn, $hRgn, $hTmp, $RGN_OR)
        _WinAPI_DeleteObject($hTmp)
    Next
    $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)
    _WinAPI_DeleteObject($hTmp)
    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)
                _WinAPI_DeleteObject($hBrush)
                _WinAPI_DeleteObject($hRgn)
                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_DeleteObject($hRgn)
                _WinAPI_EndPaint($hWnd, $tPaint)
                Return 0
        EndSwitch
    EndIf
    Return _WinAPI_CallWindowProc($hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

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

 

Link to comment
Share on other sites

  • 7 months later...

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...