Jump to content

Tab background color


ranhalt
 Share

Recommended Posts

I've got my tabbed environment working, but I don't like the white background, since I'm using bottom tabs and it looks weird. GUISetBkColor will change the background color of my GUI, but not the tab area. Any function to change it to anything else, like the standard grey?

Link to comment
Share on other sites

One of the ways...

#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $hForm, $Theme = _WinAPI_GetThemeAppProperties()

$hForm = GUICreate('MyGUI', 310, 360)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
GUICtrlCreateGroup('Group', 10, 10, 140, 95)
GUICtrlCreateCheckbox('Check1', 22, 26, 120, 23)
GUICtrlCreateCheckbox('Check2', 22, 49, 120, 23)
GUICtrlCreateCheckbox('Check3', 22, 72, 120, 23)
GUICtrlCreateGroup('Group', 160, 10, 140, 95)
GUICtrlCreateRadio('Radio1', 172, 26, 120, 23)
GUICtrlCreateRadio('Radio2', 172, 49, 120, 23)
GUICtrlCreateRadio('Radio3', 172, 72, 120, 23)
GUICtrlCreateButton('OK', 120, 330, 70, 23)
_WinAPI_SetThemeAppProperties($STAP_ALLOW_NONCLIENT)
GUICtrlCreateTab(10, 118, 292, 206)
GUICtrlCreateTabItem('Tab1')
GUICtrlCreateTabItem('Tab2')
GUICtrlCreateTabItem('')
_WinAPI_SetThemeAppProperties($Theme)

GUISetState()

Do
Until GUIGetMsg() = -3

WinAPIEx.au3

Link to comment
Share on other sites

  • 5 months later...

I believe that you can subclass the tab controls and handle their WM_ERASEBKGND event to draw the back ground. Another possibility is to use owner-drawn tab control. You can also use this -inefficient hack- trick:

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)

Local Const $FLOODFILLBORDER  = 0
Local Const $FLOODFILLSURFACE = 1

Local $hGUI, $hDC, $Tab, $hTab, $Tab1, $Tab2, $Tab3

GUIRegisterMsg($WM_PAINT, "_WM_PAINT")

$hGUI = GUICreate("Test", 300, 300)
$Tab = GUICtrlCreateTab(0, 0, 300, 300)
$hTab = GUICtrlGetHandle($Tab)
$hDC = _WinAPI_GetDC($hTab)

$Tab1 = GUICtrlCreateTabItem("Tab 1")
GUICtrlCreateEdit("", 10, 30, 280, 220)
GUICtrlCreateButton("Button 1", 115, 260, 70, 25)
$Tab2 = GUICtrlCreateTabItem("Tab 2")
GUICtrlCreateEdit("", 10, 30, 280, 220)
GUICtrlCreateButton("Button 2", 115, 260, 70, 25)
$Tab3 = GUICtrlCreateTabItem("Tab 3")
GUICtrlCreateEdit("", 10, 30, 280, 220)
GUICtrlCreateButton("Button 3", 115, 260, 70, 25)

GUICtrlCreateTabItem("")
GUISetState()
_FillTabBackground($hDC, 0xFF0000, 5, 25)

While 1
    Switch GUIGetMsg()
        Case $Tab
            Switch GUICtrlRead($Tab, 1)
                Case $Tab1
                    _WinAPI_RedrawWindow($hGUI)
                    _FillTabBackground($hDC, 0xFF0000, 5, 25)

                Case $Tab2
                    _WinAPI_RedrawWindow($hGUI)
                    _FillTabBackground($hDC, 0x00FF00, 5, 25)

                Case $Tab3
                    _WinAPI_RedrawWindow($hGUI)
                    _FillTabBackground($hDC, 0x0000FF, 5, 25)
            EndSwitch

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

_WinAPI_ReleaseDC($hTab, $hDC)
GUIDelete()

Func _WinAPI_ExtFloodFill($hDC, $iX, $iY, $iColor, $iFillType)
    Local $aResult = DllCall("gdi32.dll", "int", "ExtFloodFill", "hwnd", $hDC, "int", $iX, "int", $iY, "uint", _RGB($iColor), "uint", $iFillType)

    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[0] <> 0
EndFunc

Func _FillTabBackground($hDC, $iColor, $iX, $iY)
    Local $hBrush, $hOldBrush

    $hBrush = _WinAPI_CreateSolidBrush(_RGB($iColor))
    $hOldBrush = _WinAPI_SelectObject($hDC, $hBrush)
    _WinAPI_ExtFloodFill($hDC, $iX, $iY, 0xD4D0C8, $FLOODFILLSURFACE)
    _WinAPI_SelectObject($hDC, $hOldBrush)
    _WinAPI_DeleteObject($hBrush)
EndFunc

Func _WM_PAINT($hWnd, $iMsg, $iwParam, $ilParam)

    Switch GUICtrlRead($Tab, 1)
        Case $Tab1
            _WinAPI_RedrawWindow($hGUI, $RDW_ERASE)
            Sleep(10)
            _FillTabBackground($hDC, 0xFF0000, 5, 25)

        Case $Tab2
            _WinAPI_RedrawWindow($hGUI, $RDW_ERASE)
            Sleep(10)
            _FillTabBackground($hDC, 0x00FF00, 5, 25)

        Case $Tab3
            _WinAPI_RedrawWindow($hGUI, $RDW_ERASE)
            Sleep(10)
            _FillTabBackground($hDC, 0x0000FF, 5, 25)
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func _RGB($iColor)
    Return Dec(Hex(BinaryMid($iColor, 1, 3)))
EndFunc
Link to comment
Share on other sites

  • Moderators

MadMaxx,

3 tabs which I would like to make 3 different colours

Here is my take on how you might do it: :mellow:

#include <GUIConstantsEx.au3>
#include <GuiTab.au3>

$hGUI = GUICreate("Test", 500, 500)

$hTab_1 = GUICtrlCreateTab(10, 10, 230, 90)
    $hTab_10 = GUICtrlCreateTabitem("Red")
        _GUICtrlTab_SetBkColor($hGUI, $hTab_1, 0xFFCCCC)
    $hTab_11 = GUICtrlCreateTabitem("Green")
        _GUICtrlTab_SetBkColor($hGUI, $hTab_1, 0xCCFFCC)
    $hTab_12 = GUICtrlCreateTabitem("Blue")
        _GUICtrlTab_SetBkColor($hGUI, $hTab_1, 0xCCCCFF)
GUICtrlCreateTabitem ("")   ; end tabitem definition
GUISetState()

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

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

    Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)
    Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)

    GUICtrlCreateLabel("", $aTabPos[0]+2, $aTabPos[1]+$aTab_Rect[3]+4, $aTabPos[2]-6, $aTabPos[3]-$aTab_Rect[3]-7)
    GUICtrlSetBkColor(-1, $sBkColor)
    GUICtrlSetState(-1, $GUI_DISABLE)

EndFunc

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

MadMaxx,

My pleasure. :mellow:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 month later...

Just wanted to mention that I was very glad to find this Melba23, I have a nice blue background in my GUI and have never used CreateTab until today, I was SOOOOO upset with how my app looked because the background color was wrong. Thanks for this solution, very simple idea, I appreciate your expertise as always!!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

  • Moderators

llewxam,

Not mine, but I am afraid I have no idea who should really get the credit! :blink:

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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