Monty Posted July 21, 2008 Share Posted July 21, 2008 I am currently workging with tabs. I have set back ground color but the portion of the tab remains grey (default color). How can I change this color. The attachment is just an example to show the color that I am wishing to change. Link to comment Share on other sites More sharing options...
martin Posted July 21, 2008 Share Posted July 21, 2008 (edited) I am currently workging with tabs. I have set back ground color but the portion of the tab remains grey (default color). How can I change this color. The attachment is just an example to show the color that I am wishing to change.Example Edited July 21, 2008 by martin 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. Link to comment Share on other sites More sharing options...
Monty Posted July 21, 2008 Author Share Posted July 21, 2008 Thank you for that example. What I am really after though is that little portion of grey right next to "tab2". How can I change this color. I am sorry if I overlooked any commands from the example you pointed out. Thanks. Link to comment Share on other sites More sharing options...
rasim Posted July 21, 2008 Share Posted July 21, 2008 You need to create the ownerdraw Tab control expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> Global Const $ODT_TAB = 101 Global Const $ODS_SELECTED = 0x0001 Global Const $ODA_DRAWENTIRE = 0x1 Global Const $ODS_FOCUS = 0x0010 $hGUI = GUICreate("Draw Tab", 300, 200) $hTab = GUICtrlCreateTab(10, 10, 280, 180, $TCS_OWNERDRAWFIXED) $TabItem_1 = GUICtrlCreateTabItem("TabItem 1") GUICtrlCreateLabel("", 10, 33, 277, 155) GUICtrlSetBkColor(-1, 0xDDAA11) GUICtrlSetState(-1, $GUI_DISABLE) $TabItem_2 = GUICtrlCreateTabItem("TabItem 2") GUICtrlCreateLabel("", 10, 33, 277, 155) GUICtrlSetBkColor(-1, 0x99BBEE) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateTabItem("") GUISetState() GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") _GUICtrlTab_SetCurSel($hTab, 1) _GUICtrlTab_SetCurSel($hTab, 0) Do Until GUIGetMsg() = -3 Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $DRAWITEMSTRUCT $DRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _ "hwnd hItm;hwnd hDC;dword itmRect[4];dword itmData", $lParam) If DllStructGetData($DRAWITEMSTRUCT, "cType") <> $ODT_TAB Then Return $GUI_RUNDEFMSG Local $cID = DllStructGetData($DRAWITEMSTRUCT, "cID") Local $itmID = DllStructGetData($DRAWITEMSTRUCT, "itmID") Local $itmAction = DllStructGetData($DRAWITEMSTRUCT, "itmAction") Local $itmState = DllStructGetData($DRAWITEMSTRUCT, "itmState") Local $hItm = DllStructGetData($DRAWITEMSTRUCT, "hItm") Local $hDC = DllStructGetData($DRAWITEMSTRUCT, "hDC") If $itmAction <> $ODA_DRAWENTIRE Then Return $GUI_RUNDEFMSG Local $iTextColor, $itmText Switch $itmID Case 0 $iBrushColor = 0x11AADD Case 1 $iBrushColor = 0xEEBB99 EndSwitch DLLCall("gdi32.dll","int","SetBkMode", "hwnd", $hDC, "int", 1) Local $iBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor) $iBrush = $iBrush[0] Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush) DLLCall("user32.dll","int","FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "hwnd", $iBrush) Local $tBuffer = DllStructCreate("char[256]") DllStructSetData($tBuffer, 1, "Item" & $itmID) $itmText = DllStructGetData($tBuffer, 1) DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 1) + 10, 1) DllStructSetData($DRAWITEMSTRUCT, "itmRect", DllStructGetData($DRAWITEMSTRUCT, "itmRect", 2) + 5, 2) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $itmText, "int", StringLen($itmText), _ "ptr", DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"), "int", $DT_LEFT) _WinAPI_SelectObject($hDC, $iBrushOld) _WinAPI_DeleteObject($iBrush) Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
martin Posted July 21, 2008 Share Posted July 21, 2008 @rasim That's a nice example, thanks for that rasim. But it doesn't get over the problem Monty has which I also overlooked. @Monty The easiest way I know to get rid of the incorrect background is to make a label the correct size to cover that area and make the background colour of the label match the gui background. Like this expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Example() Func Example() Local $tab, $tab0, $tab0OK, $tab0input Local $tab1, $tab1combo, $tab1OK Local $tab2, $tab2OK, $msg, $labcover GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered GUISetBkColor(0x00E0FFFF) GUISetFont(9, 300) $tab = GUICtrlCreateTab(10, 10, 200, 100) $tab0 = GUICtrlCreateTabItem("tab0") GUICtrlCreateLabel("label0", 30, 80, 50, 20) $tab0OK = GUICtrlCreateButton("OK0", 20, 50, 50, 20) $tab0input = GUICtrlCreateInput("default", 80, 50, 70, 20) $tab1 = GUICtrlCreateTabItem("tab----1") GUICtrlCreateLabel("label1", 30, 80, 50, 20) $tab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120) GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon"); default Jon $tab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20) $tab2 = GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) ; will be display first GUICtrlCreateLabel("label2", 30, 80, 50, 20) $tab2OK = GUICtrlCreateButton("hide label", 120, 50, 80) GUICtrlCreateTabItem("") ; end tabitem definition $labcover = GUICtrlCreateLabel("",150,10,80,22) GUICtrlSetBkColor(-1,0x00E0FFFF) GUICtrlCreateLabel("label3", 20, 130, 50, 20) GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $tab2OK Then GUICtrlSetState($labcover,$GUI_HIDE) If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc 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. Link to comment Share on other sites More sharing options...
Monty Posted July 22, 2008 Author Share Posted July 22, 2008 That works, and is certainly a neat trick. Thanks to everyone for helping out. Really appreciate it. Link to comment Share on other sites More sharing options...
therks Posted July 22, 2008 Share Posted July 22, 2008 What about tab size changing based on font settings? I'm just thinking if someone has set their fonts quite large then the tab would be larger and a statically sized label would no longer fit properly... right? My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Monty Posted July 22, 2008 Author Share Posted July 22, 2008 (edited) I beleive the tab sizes will automatically change depending in the font size. You can also include scroll at the end. CODE#include <GUIConstants.au3> #include <TabConstants.au3> GUICreate("Test", 580, 400, 105, 475) $font="Century Gothic" GUISetFont (20, 550, 0, $font) $tab = GUICtrlCreateTab(30, 30, 520, 340, $TCS_RAGGEDRIGHT) $tab1 = GUICtrlCreateTabItem("01") $tab2 = GUICtrlCreateTabItem("02") $tab3 = GUICtrlCreateTabItem("03") $tab4 = GUICtrlCreateTabItem("04") $tab5 = GUICtrlCreateTabItem("05") $tab6 = GUICtrlCreateTabItem("06") $tab7 = GUICtrlCreateTabItem("07") $tab8 = GUICtrlCreateTabItem("08") GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect Wend Edited July 22, 2008 by Monty Link to comment Share on other sites More sharing options...
martin Posted July 23, 2008 Share Posted July 23, 2008 What about tab size changing based on font settings? I'm just thinking if someone has set their fonts quite large then the tab would be larger and a statically sized label would no longer fit properly... right?Yes you are correct, so to do the job properly you need to use _GUICtrlTab_GetItemRect for each tab and find out what size the label needs to be. 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. Link to comment Share on other sites More sharing options...
MachinistProgrammer Posted March 10, 2013 Share Posted March 10, 2013 what about if you have new tabs e.g. the tabs in scite? All my projects live on github Link to comment Share on other sites More sharing options...
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