HezzelQuartz Posted October 2, 2024 Posted October 2, 2024 How to change GUI tab background color? I tried using GUICtrlSetBkColor(-1,0xFF0000), but it didn't work expandcollapse popup#include <GUIConstantsEx.au3> $Form1_1 = GUICreate("My Test GUI", 623, 449, -1, -1) $Tab1 = GUICtrlCreateTab(16, 16, 585, 417) ;~ Main Tab ===================================== $MainTabSheet = GUICtrlCreateTabItem("Main") $ExitButtonM = GUICtrlCreateButton("Exit", 504, 392, 81, 28) ;~ Input Tab ===================================== $InputTabSheet = GUICtrlCreateTabItem("Input") GUICtrlSetBkColor(-1,0xFF0000) GUICtrlSetState(-1, $GUI_SHOW) $SingleFileRadio = GUICtrlCreateRadio("Select Single File", 24, 56, 180, 20) $SingleFileLocText = GUICtrlCreateLabel(IniRead("MyGUI.ini", "Main", "InputFileName", " "), 24, 80, 400, 84) $SingleFileSelectButton = GUICtrlCreateButton("Select", 430, 80, 73, 28) $SingleFileEditButton = GUICtrlCreateButton("Edit", 518, 80, 73, 28) $ExitButtonI = GUICtrlCreateButton("Exit", 504, 392, 81, 28) $RunButtonI = GUICtrlCreateButton("Run", 24, 392, 81, 28) $MultipleFileRadio = GUICtrlCreateRadio("Select Multiple Files", 24, 176, 180, 20) $FolderRadio = GUICtrlCreateRadio("Select Folder", 24, 296, 180, 20) GUICtrlCreateTabItem("") ;~ Filter Tab ===================================== $FiltersTabSheet = GUICtrlCreateTabItem("Filters") $RunButtonF = GUICtrlCreateButton("Run", 24, 392, 81, 28) $ExitButtonF = GUICtrlCreateButton("Exit", 504, 392, 81, 28) ;~ Output Tab ===================================== $OutputTabSheet = GUICtrlCreateTabItem("Output") $RunButtonO = GUICtrlCreateButton("Run", 24, 392, 81, 28) $ExitButtonO = GUICtrlCreateButton("Exit", 504, 392, 81, 28) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg ; You can have multiple cases with a common action Case $GUI_EVENT_CLOSE, $ExitButtonM, $ExitButtonI, $ExitButtonF, $ExitButtonO Exit Case $SingleFileRadio ;IniWrite("MyGUI.ini", "Main", "InputRadio", 1) Case $MultipleFileRadio ;IniWrite("MyGUI.ini", "Main", "InputRadio", 2) Case $FolderRadio ;IniWrite("MyGUI.ini", "Main", "InputRadio", 3) Case $SingleFileSelectButton ; Select the tab on which to create the control GUISwitch($Form1_1, $InputTabSheet) ; Create the control $SingleFileLocText = GUICtrlCreateLabel("Now I appear on only the input tab", 24, 80, 400, 84) GUICtrlSetBkColor($SingleFileLocText, 0xFFCCCC) ; Close the tab creation mode and reset the current GUI GUICtrlCreateTabItem("") GUISwitch($Form1_1) EndSwitch WEnd I want to change the white background shown in input tab into bright red color, but not working
Nine Posted October 2, 2024 Posted October 2, 2024 (edited) Here one way : expandcollapse popup#include <WinAPIGdiDC.au3> #include <GuiConstants.au3> #include <GuiTab.au3> #include <GuiListView.au3> Opt("MustDeclareVars", True) Global Const $ODT_TAB = 101 Global Const $ODA_DRAWENTIRE = 1 Global Const $tagDRAWITEMSTRUCT = "uint cType;uint cID;uint itmID;uint itmAction;uint itmState;hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData" Main() Func Main() Local $hGUI = GUICreate("OwnerDraw Tabs", 300, 200) Local $idTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED) Local $TabItem_1 = GUICtrlCreateTabItem("TabItem 1") SetTabColor($hGUI, $idTab, 0xDDAA11) GUICtrlCreateButton("OK1", 50, 100, 80, 20) Local $TabItem_2 = GUICtrlCreateTabItem("TabItem 2") SetTabColor($hGUI, $idTab, 0x99BBEE) GUICtrlCreateButton("OK2", 100, 100, 80, 20) GUICtrlCreateTabItem("") GUISetState() GUIRegisterMsg($WM_DRAWITEM, WM_DRAWITEM) _GUICtrlTab_SetCurSel($idTab, 1) _GUICtrlTab_SetCurSel($idTab, 0) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>Main Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $tDrawItem = DllStructCreate($tagDRAWITEMSTRUCT, $lParam) If $tDrawItem.cType <> $ODT_TAB Or $tDrawItem.itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG Local $iItmID = $tDrawItem.itmID, $hDC = $tDrawItem.hDC, $iBrushColor, $tRect Switch $iItmID Case 0 $iBrushColor = 0x11AADD Case 1 $iBrushColor = 0xEEBB99 EndSwitch _WinAPI_SetBkMode($hDC, 1) Local $hBrush = _WinAPI_CreateSolidBrush($iBrushColor) $tRect = DllStructCreate($tagRect, DllStructGetPtr($tDrawItem, "itmRect")) _WinAPI_FillRect($hDC, $tRect, $hBrush) $tRect.left += 5 $tRect.top += 5 _WinAPI_DrawText($hDC, _GUICtrlTab_GetItemText($tDrawItem.cID, $iItmID), $tRect, $DT_LEFT) _WinAPI_DeleteObject($hBrush) Return $GUI_RUNDEFMSG EndFunc ;==>WM_DRAWITEM Func SetTabColor($hWnd, $idTab, $nColor) Local $aPos = ControlGetPos($hWnd, "", $idTab) Local $aRect = _GUICtrlTab_GetItemRect($idTab, -1) GUICtrlCreateLabel("", $aPos[0] + 2, $aPos[1] + $aRect[3] + 4, $aPos[2] - 4, $aPos[3] - $aRect[3] - 6) GUICtrlSetBkColor(-1, $nColor) GUICtrlSetState(-1, $GUI_DISABLE) EndFunc ;==>_GUICtrlTab_SetBkColor Edited October 2, 2024 by Nine better code v2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now