Jump to content

How to change tab color and resize if tab2 selected


Recommended Posts

Hello

Sorry for such newbish question, I just started to use autoit, did some very simple scripts with autohotkey but thats it.

So I decided to write a log parser and so far I managed to do _FileListToArray and fill that data in combobox dropdown :)

OK back to the topic, I would like to have form with black background, and I had it until I implemented TABs so I can have Main and settings.

Now I searched in help file but dont see any color options.

My 2nd question: Is it possible to resize gui so let say when iam on Main Window Gui size= 300x600 and when I click on settings Gui size = 300x300.

I would really appreciate any help you can give me.

Link to comment
Share on other sites

Hope this help:

#include <GuiConstants.au3>

Opt("GuiResizeMode", $GUI_DOCKAUTO)

Global $Select = False

$hGUI = GUICreate("Test GUI", 300, 200)
GUISetBkColor(0xDDDDDD)

$hTab = GUICtrlCreateTab(10, 10, 280, 180)

$TabItem1 = GUICtrlCreateTabItem("TabItem 1")

GUICtrlCreateLabel("", 10, 33, 277, 155)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetState(-1, $GUI_DISABLE)

$TabItem2 = GUICtrlCreateTabItem("TabItem 2")
GUICtrlCreateLabel("", 10, 33, 277, 155)
GUICtrlSetBkColor(-1, 0xFF0000)
GUICtrlSetState(-1, $GUI_DISABLE)

GUICtrlCreateTabItem("")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
    
    If (GUICtrlRead($hTab, 1) = $TabItem2) And ($Select = False) Then
        $Select = True
        $aPos = WinGetPos($hGUI)
        WinMove($hGUI, "", $aPos[0], $aPos[1], 300, 300)
    ElseIf (GUICtrlRead($hTab, 1) <> $TabItem2) And ($Select = True) Then
        $Select = False
        $aPos = WinGetPos($hGUI)
        WinMove($hGUI, "", $aPos[0], $aPos[1], 300, 200)
    EndIf
WEnd
Link to comment
Share on other sites

/bump

Anyone know if its possible to color tabs too ( in current example TabItem1 and TabItem2)

Its no easy way. You need to draw Tab item text and color.

Example:

#include <GuiConstants.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

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