Jump to content

Recommended Posts

Posted

Does anyone know how to get rid of it?

Posted Image

GUICreate('MyGUI', 300, 300)
GUISetBkColor(0xAACCFF)
GUICtrlCreateTab(20, 20, 260, 260)
GUICtrlCreateTabItem('Item1')
GUICtrlCreateTabItem('Item2')
GUICtrlCreateTabItem('')
GUISetState()

Do
Until GUIGetMsg() = -3
Posted

I assume you have to create a label with the same color as the gui background to put on tab.

Have a look to OwnTab-UDF from funkey.

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Thanks, but I'm interested in native solution, not a trick. I can not understand where Tab takes the background color. If I write the following

_WinAPI_SetClassLongEx($hTab, $GCL_HBRBACKGROUND, _WinAPI_CreateSolidBrush(0xFFCCAA))

still nothing happens...

:)

Of course, I can draw your own skin or use a Windows theme, but it is quite time-consuming solution.

Posted

  On 4/1/2011 at 8:02 PM, 'Yashied said:

Thanks, but I'm interested in native solution, not a trick. I can not understand where Tab takes the background color. If I write the following

I thgink that the tab control uses the default windows background colour so you could change that I suppose.

Having seen the same question asked over the years and seen SmOke_N's attempts (failed) to get round it I am fairly sure you won't find a native solution. That is why Delphi (which I use) has it's own nice tab control which doesn't have all problems the windows one has.

One way to avoid the wrong color at the top left is to set the tab widths so they fill the width of the tab control. Placing a label over the offending area works quite well but you have to adjust the position of the label depending on which tab is selected to maintain a neat result. I think the windows tab control is very poor. If you try having tabs at the sides instead of the top you will conclude that the designers were about to leave to start work at Apple.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted

While nothing is better not come up. Works under Windows Vista/7.

Posted Image

#Include <Constants.au3>
#Include <GUITab.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_GETIMAGE = 0x0173
Global Const $PRF_CLIENT = 0x04

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

GUICreate('MyGUI', 300, 300)
GUICtrlCreatePic(@ScriptDir & '\Tech.bmp', 0, 0, 300, 300, $WS_CLIPCHILDREN)
$hPic = GUICtrlGetHandle(-1)
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_SetWindowLongEx($hTab, $GWL_WNDPROC, $pDll)

_WinAPI_SetParent($hTab, $hPic)

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 $tRect[2]
                Local $hParent = _WinAPI_GetParent($hWnd)
                Local $hRgn = _CreateClipRgn($hWnd)
                Local $hPrev = _WinAPI_GetClipRgn($wParam)
                $tRect[0] = _WinAPI_GetWindowRect($hParent)
                $tRect[1] = _WinAPI_GetWindowRect($hWnd)
                _WinAPI_ExtSelectClipRgn($wParam, $hRgn, $RGN_DIFF)
                _WinAPI_DrawBitmap($wParam, DllStructGetData($tRect[0], 1) - DllStructGetData($tRect[1], 1), DllStructGetData($tRect[0], 2) - DllStructGetData($tRect[1], 2), _SendMessage($hParent, $STM_GETIMAGE))
                _WinAPI_SelectClipRgn($wParam, $hPrev)
                _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_SetWindowLongEx($hTab, $GWL_WNDPROC, $hProc)
    DllCallbackFree($hDll)
EndFunc   ;==>AutoItExit

Tech.bmp

Posted

Nice solution / workaround Yashied! :)

Instead using a bitmap you can create a bitmap with same color as the background.

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Without bitmap.

#Include <Constants.au3>
#Include <GUITab.au3>
#Include <WinAPIEx.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_SetWindowLongEx($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_SetWindowLongEx($hTab, $GWL_WNDPROC, $hProc)
    DllCallbackFree($hDll)
EndFunc   ;==>AutoItExit
Posted

I need these includes

#include <Constants.au3>
#include <GuiTab.au3>
#include <TabConstants.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

and have to add Local Const $WM_PRINTCLIENT = 0x0318 to _WinProc() functions!

Nice, nice, nice!

Br,

UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

It's brilliant Yashied. I like it a lot :)

Since a solution to this has been asked so often I think you should put it in example scripts.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Posted (edited)
Posted

  On 4/3/2011 at 11:16 PM, 'Yashied said:

Unfortunately, in XP will need to create a slightly different clip region (rounded corners). Also, it may depend on the used Windows theme.

You mean that one pixel in the corner? I would think the 1 pixel wide space between tabs is worse.

Also when you disable theming the color overflow the tab.

Screenshots

  • 2 years later...
Posted

I do not have the WinAPIEx.au3 in my install. Where can I find this to use this example?  Trying to over come this issue where I am using custom colors and I don't want the default grey theme.

I've tried painting a colored label, but then the tabs (button style) aren't visible until you click on them (example, below).

GUICtrlCreateLabel("", 0, 120, 751, 320)
GUICtrlSetBkColor(-1, $iContentArea)
GUICtrlSetState(-1, $GUI_DISABLE)

  • Moderators
Posted

LeviStevens,

The WinAPIEx UDF is included with the 3.3.9.x Beta installs. I suggest you download one of them. :)

But I use something like this to produce coloured tabs: ;)

#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>

; Tab colours
Global $aTabColours[4] = [0xFFC0C0, 0xC0FFC0, 0xC0C0FF, 0xC0C0C0]

; Create GUI
Global $hGUI = GUICreate ("Test", 400,300)
GUISetBkColor (0)

; Create label to cover tab "tab"
Global $hColourTab = GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))

; Create tab
Global $hTab = GUICtrlCreateTab(5, 5,390, 290)
Global $hTab_Handle = GUICtrlGetHandle($hTab)

; Create tab items and colour them
For $i = 0 To 3
    GUICtrlCreateTabItem ("Tab item - " & $i)
    _GUICtrlTab_SetBkColor($hGUI, $hTab, $aTabColours[$i])
    GUICtrlCreateTabItem ("")
Next

_GUICtrlTab_SetCurSel($hTab_Handle,0)
_GUICtrlTab_SetCurFocus($hTab_Handle,0)
TabEvent()

GUISetState ()

While 1
    Switch GUIGetMsg ()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hTab
            TabEvent()
    EndSwitch
WEnd

Func TabEvent()

    ; Set values
    Local $iTab_X = 5, $iTab_Y = 5, $iTab_Margin = 1
    ; Get index of current tab
    Local $iTab_Index = GUICtrlRead($hTab)
    ; Get coordinates of TabItem
    Local $aTab_Coord = _GUICtrlTab_GetItemRect($hTab_Handle, $iTab_Index)
    ; Get text of TabItem
    Local $sTab_Text = _GUICtrlTab_GetItemText($hTab_Handle, $iTab_Index)
    ; Place label
    GUICtrlSetPos($hColourTab, $iTab_X + $aTab_Coord[0] + $iTab_Margin, $iTab_Y + $aTab_Coord[1] + $iTab_Margin, $aTab_Coord[2] - $aTab_Coord[0] - ($iTab_Margin * 2), $aTab_Coord[3] - $aTab_Coord[1] - ($iTab_Margin * 2) + 5)
    ; Set text
    GUICtrlSetData($hColourTab, $sTab_Text)
    ; Set colour
    GUICtrlsetBkColor ($hColourTab,$aTabColours[$iTab_Index] )
    ; Set focus
    _GUICtrlTab_SetCurFocus($hTab_Handle,$iTab_Index)

EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)

    ; Get tab position
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)
    ; Get size of user area
    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)
    ; Create label
    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + $aTab_Rect[3] + 4, $aTabPos[2] - 6, $aTabPos[3] - $aTab_Rect[3] - 7)
    ; Colour label
    GUICtrlSetBkColor(-1, $sBkColor)
    ; Disable label
    GUICtrlSetState(-1, $GUI_DISABLE)

EndFunc   ;==>_GUICtrlTab_SetBkColor
Any use? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

  • 1 year later...
Posted

When I run this, it does not repaint the controls I place inside of the tab control. 

For example a listview, the columns are not visible - once I mouse over them they are painted. 

What can I do to make this behave normally?

  • Moderators
Posted (edited)

JakeJohnson74,

Works fine for me: :)

#include <GuiConstantsEx.au3>
#include <GuiTab.au3>
#include <StaticConstants.au3>

; Tab colours
Global $aTabColours[4] = [0xFFC0C0, 0xC0FFC0, 0xC0C0FF, 0xC0C0C0]

; Create GUI
Global $hGUI = GUICreate ("Test", 500, 500)

; Create label to cover tab "tab"
Global $hColourTab = GUICtrlCreateLabel("", 0, 0, 1, 1, BitOR($SS_NOTIFY, $SS_CENTER, $SS_SUNKEN))

; Create tab
Global $hTab = GUICtrlCreateTab(10, 10, 400, 300)
Global $hTab_Handle = GUICtrlGetHandle($hTab)

; Create tab items and colour them
For $i = 0 To 3
    GUICtrlCreateTabItem ("Tab item - " & $i)
    _GUICtrlTab_SetBkColor($hGUI, $hTab, $aTabColours[$i]) ; Are you creating the coloured background first? <<<<<<<<<<<<<<<<<<<
    GUICtrlCreateButton("Button " & $i, 50 + (80 * $i), 50, 80, 30)
    GUICtrlCreateListView("Col " & $i, 50, 100, 200, 100)
    GUICtrlCreateTabItem ("")
Next

_GUICtrlTab_SetCurSel($hTab_Handle,0)
_GUICtrlTab_SetCurFocus($hTab_Handle,0)
TabEvent()

GUISetState ()

While 1
    Switch GUIGetMsg ()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hTab
            TabEvent()
    EndSwitch
WEnd

Func TabEvent()

    ; Set values
    Local $iTab_X = 10, $iTab_Y = 10, $iTab_Margin = 1
    ; Get index of current tab
    Local $iTab_Index = GUICtrlRead($hTab)
    ; Get coordinates of TabItem
    Local $aTab_Coord = _GUICtrlTab_GetItemRect($hTab_Handle, $iTab_Index)
    ; Get text of TabItem
    Local $sTab_Text = _GUICtrlTab_GetItemText($hTab_Handle, $iTab_Index)
    ; Place label
    GUICtrlSetPos($hColourTab, $iTab_X + $aTab_Coord[0] + $iTab_Margin, $iTab_Y + $aTab_Coord[1] + $iTab_Margin, $aTab_Coord[2] - $aTab_Coord[0] - ($iTab_Margin * 2), $aTab_Coord[3] - $aTab_Coord[1] - ($iTab_Margin * 2) + 5)
    ; Set text
    GUICtrlSetData($hColourTab, $sTab_Text)
    ; Set colour
    GUICtrlsetBkColor ($hColourTab,$aTabColours[$iTab_Index] )
    ; Set focus
    _GUICtrlTab_SetCurFocus($hTab_Handle,$iTab_Index)

EndFunc

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)

    ; Get tab position
    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)
    ; Get size of user area
    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)
    ; Create label
    GUICtrlCreateLabel("", $aTabPos[0] + 2, $aTabPos[1] + $aTab_Rect[3] + 4, $aTabPos[2] - 6, $aTabPos[3] - $aTab_Rect[3] - 7)
    ; Colour label
    GUICtrlSetBkColor(-1, $sBkColor)
    ; Disable label
    GUICtrlSetState(-1, $GUI_DISABLE)

EndFunc   ;==>_GUICtrlTab_SetBkColor
M23 Edited by Melba23
Wrong button too soon!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

@Melba

Haha it would probably help if I referenced the code I was talking about! haha Sorry :)

It was Yashied's example. Yours does, in fact, work fine. Actually... I think I might just use that instead!  :shifty: It will just take a little cannibalizing because I only need just the area to the right of the tabs. 

Edited by JakeJohnson74
  • Moderators
Posted

JakeJohnson74,

No probs. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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