Jump to content

TabPage Set Font


Recommended Posts

Hi,

i did some researchs how to set the font and the only way is to overwrite the subclass with WM_DRAWITEM. With WM_SETFONT i can only change the font for all tab pages, but i want to change the font for a specific page.

So i have to set the $TCS_OWNERDRAWFIXED style to the tab control to send the WM_DRAWITEM message to the parent window. When i set this style, i can change the fonts, but sadly the tab looses the nice and simple "AutoIt style". I created two child guis, the first is the owner draw tab and the second the "Normal" tab.

My questions is, how to create this special "AutoIt style"???

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <ColorConstants.au3>


Global Const $ODT_TAB = 101
Global Const $ODS_SELECTED = 0x0001
Global Const $ODA_DRAWENTIRE = 0x1

Global Const $ODS_FOCUS = 0x0010

$hStrikeOutDefaultFont = _WinAPI_CreateFont(14, 0, 0, 0, 400, False, False, True) ; see system apps module


$hGUI = GUICreate("Draw Tab", 500, 600)

 ; Create child GUIs to hold tabs
 $hTab_Win0 = GUICreate("", 400, 200, 50, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_0 = GUICtrlCreateTab(10, 10, 380, 180, $TCS_OWNERDRAWFIXED);BitOR($TCS_OWNERDRAWFIXED, $TCS_TOOLTIPS, $WS_TABSTOP, $WS_CLIPSIBLINGS))
     $hTab_00 = GUICtrlCreateTabitem("00")
         GUICtrlCreateButton("00", 160, 90, 80, 30)
     $hTab_01 = GUICtrlCreateTabitem("01")
         GUICtrlCreateButton("01", 160, 90, 80, 30)

 GUICtrlCreateTabitem ("")
 GUISetState()


 $hTab_Win1 = GUICreate("", 400, 200, 50, 250, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
 $hTab_1 = GUICtrlCreateTab(10, 10, 380, 180)
     $hTab_10 = GUICtrlCreateTabitem("10")
         GUICtrlCreateButton("10", 160, 90, 80, 30)
     $hTab_11 = GUICtrlCreateTabitem("11")
         GUICtrlCreateButton("11", 160, 90, 80, 30)
 GUICtrlCreateTabitem ("")
 GUISetState()



GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
;~ GUIRegisterMsg($WM_SETFONT, "WM_SETFONT")

;~ GUICtrlSendMsg ( $hTab_1, $WM_SETFONT , $hStrikeOutDefaultFont, 1 )


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


 Func WM_SETFONT($hWnd, $Msg, $wParam, $lParam)

    ConsoleWrite("$hWnd: " & $hWnd & " $Msg: " & $Msg & " $wParam: " & $wParam & " $lParam: " & $lParam & @CRLF)
EndFunc


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
    $iTextColor = 0xFFFFFF

    Switch $itmID
        Case 0
            $iBrushColor = 0x11AADD
        Case 1
            $iBrushColor = 0xEEBB99
    EndSwitch

    _WinAPI_SetBkMode($hDC, $TRANSPARENT)

    Local $iBrush = _WinAPI_CreateSolidBrush($iBrushColor)
    Local $iBrushOld = _WinAPI_SelectObject($hDC, $iBrush)

    $g_tRECT = DllStructCreate($tagRect, DllStructGetPtr($DRAWITEMSTRUCT, "itmRect"))
    DllStructSetData($g_tRECT, "Left", DllStructGetData($g_tRECT, "Left"))
    DllStructSetData($g_tRECT, "Top", DllStructGetData($g_tRECT, "Top"))
    DllStructSetData($g_tRECT, "Right", DllStructGetData($g_tRECT, "Right"))
    DllStructSetData($g_tRECT, "Bottom", DllStructGetData($g_tRECT, "Bottom")+10)

    _WinAPI_FillRect ( $hDC, $g_tRECT, $iBrush )

    _WinAPI_SetTextColor($hDC, $iTextColor)

    _WinAPI_DrawText($hDC, "Item " & $itmID, $g_tRECT, $DT_LEFT)

    _WinAPI_SelectObject($hDC, $iBrushOld)
    _WinAPI_DeleteObject($iBrush)

    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_DRAWITEM

Thanks in advance

Edited by Trolleule
Link to comment
Share on other sites

did you mean a result like this:

#include <GUIConstantsEx.au3>

Example()

Func Example()
    GUICreate("My GUI Tab") ; will create a dialog box that when displayed is centered

    GUISetBkColor(0x00E0FFFF)

    GUICtrlCreateTab(10, 10, 200, 100)

    GUICtrlCreateTabItem("tab0")
    GUISetFont(9, 300)
    GUICtrlCreateLabel("label0", 30, 80, 50, 20)
    GUICtrlCreateButton("OK0", 20, 50, 50, 20)
    GUICtrlCreateInput("default", 80, 50, 70, 20)

    GUICtrlCreateTabItem("tab----1")
    GUISetFont(10, 500)
    GUICtrlCreateLabel("label1", 30, 80, 50, 20)
    GUICtrlCreateCombo("", 20, 50, 60, 120)
    GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo|guinness", "Jon") ; default Jon
    GUICtrlCreateButton("OK1", 80, 50, 50, 20)

    GUICtrlCreateTabItem("tab2")
    GUICtrlSetState(-1, $GUI_SHOW) ; will be display first
    GUISetFont(12, 700)
    GUICtrlCreateLabel("label2", 30, 80, 50, 20)
    GUICtrlCreateButton("OK2", 140, 50, 50)

    GUICtrlCreateTabItem("") ; end tabitem definition

    GUICtrlCreateLabel("label3", 20, 130, 50, 20)

    GUISetState(@SW_SHOW)

    Local $idMsg
    ; Loop until the user exits.
    While 1
        $idMsg = GUIGetMsg()

        If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

have also a look at https://autoit.de/index.php/Thread/15644-Eigenes-Tab-Register-OwnTab-UDF/

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

×
×
  • Create New...