Announcement

Collapse
No announcement yet.

Tab control tab font question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tab control tab font question

    Trying to work out how to change the font used in the tab part of a tab control. Is this possible without ownerdrawing the tab control? WM_SETFONT does not appear to do the job. Looking at the TCM_ messages, there is nothing obviously helpful.

  • #2
    this is an excerpt from QTAB....

    Code:
        '---CHANGE MAIN TAB FONT...
        IF lfApply.lfHeight THEN
            'create the new font using the LOGFONT structure...
    
            hDC& = GetDC(hDlg)
                fpt& = (lfApply.lfHeight * 72) / -GetDeviceCaps(hDC&, %LOGPIXELSY)
            ReleaseDC hDlg, hDC&
    
            hFont& = MakeFontEx(lfApply.lfFaceName,fpt&,lfApply.lfWeight,lfApply.lfItalic,lfApply.lfUnderline,lfApply.lfStrikeOut)
    
            IF hFont& THEN
                DeleteObject ghTabFont
                ghTabFont = hFont&
                SendMessage ghWndTab, %WM_SETFONT,ghTabFont,0
    
                'resize all the FORMS/CLIENTS
                CALL SizeClientOnTabs()
    
                'Draw our Handles at the new locations...
                CALL DrawTabGripHandles(ghMainClient,ghWndTab,ghTabGrip())
            END IF
        END IF
    Last edited by Jules Marchildon; 3 May 2008, 06:59 AM.
    Best regards
    Jules
    www.rpmarchildon.com

    Comment


    • #3
      Jules, Thanks for the example which I regret I am too stupid to use. I see but am still "all at sea".

      This code shows the problem, and the WM_SETFONTs show my attempt to solve it:

      Code:
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "WIN32API.INC"
      #INCLUDE "COMMCTRL.INC"
      %IDC_SYSTAB                    = 1010
      %IDC_PORT_LAB                  = 1014
      %IDC_STBD_LAB                  = 1026
      GLOBAL ghTabDlg() AS LONG
      GLOBAL ghfont AS LONG
      GLOBAL ghfont1 AS LONG
      %dlgPORT = 0
      %dlgSTBD = 1
      %color_PORT = %RED
      %color_STBD = %GREEN
      '------------------------------------------------------------------------------------
      FUNCTION MakeFont(BYVAL fName AS STRING, BYVAL ptSize AS LONG, _
                        OPT BYVAL attr AS STRING) AS DWORD
         '--------------------------------------------------------------------
         ' Create a desired font and return its handle.
         ' attr = "biu" for bold, italic, and underlined (any order)
         '--------------------------------------------------------------------
         LOCAL hDC AS DWORD, CharSet AS LONG, CyPixels AS LONG
         LOCAL bold, italic, uLine AS LONG
         IF LEN(attr) THEN
            IF INSTR(LCASE$(attr), "b") THEN bold = %FW_BOLD
            IF INSTR(LCASE$(attr), "i") THEN italic = 1
            IF INSTR(LCASE$(attr), "u") THEN uLine = 1
         END IF
         hDC = GetDC(%HWND_DESKTOP)
         CyPixels  = GetDeviceCaps(hDC, %LOGPIXELSY)
         ReleaseDC %HWND_DESKTOP, hDC
         PtSize = 0 - (ptSize * CyPixels) \ 72
         FUNCTION = CreateFont(ptSize, 0, 0, 0, bold, italic, uLine, _
                   %FALSE, CharSet, %OUT_TT_PRECIS, _
                   %CLIP_DEFAULT_PRECIS, %DEFAULT_QUALITY, _
                   %FF_DONTCARE , BYCOPY fName)
      END FUNCTION
      '-----------------------------------------------------------------------------------
      CALLBACK FUNCTION ShowDIALOG1Proc()
          LOCAL s AS STRING
          LOCAL l, lcurrlen AS LONG
          LOCAL TI            AS TC_ITEM
          LOCAL  pNMHDR    AS NMHDR PTR
          LOCAL  pTT       AS TOOLTIPTEXT PTR
          LOCAL  Result    AS LONG
          LOCAL  HT        AS TC_HITTESTINFO
          STATIC szText    AS ASCIIZ * 64
      
          SELECT CASE AS LONG CBMSG
      
              CASE %WM_INITDIALOG
                  ' Add tabs to the SYSTAB control
                  TI.Mask = %TCIF_TEXT    ' Text field is valid
                  TI.iImage = -1          ' no image
                  s = "PORT"
                  TI.pszText = STRPTR(s)
                  CONTROL SEND CBHNDL, %IDC_SYSTAB, %WM_SETFONT, ghfont, 0
                  CONTROL SEND CBHNDL, %IDC_SYSTAB, %TCM_INSERTITEM, 0, VARPTR(TI)
                  s = "STBD"
                  TI.pszText = STRPTR(s)
                  CONTROL SEND CBHNDL, %IDC_SYSTAB, %WM_SETFONT, ghfont, 0
                  CONTROL SEND CBHNDL, %IDC_SYSTAB, %TCM_INSERTITEM, 1, VARPTR(TI)
                  DIALOG SHOW STATE ghTabDlg(0), %SW_SHOW
                  '
               CASE %WM_NOTIFY
      
                   ' Handle Notify messages for tooptips and tab page changes
                   pNMHDR = CBLPARAM
      
                   ' Is it a page change message?
                   IF @pNMHDR.hWndFrom = GetDlgItem(CBHNDL, %IDC_SYSTAB) THEN
      
                       ' Get the current tab page number (zero based)
                       CONTROL SEND CBHNDL, %IDC_SYSTAB, %TCM_GETCURSEL, 0, 0 TO Result
      
                       SELECT CASE @pNMHDR.Code
                       CASE %TCN_SELCHANGING ' The page is about to change
                           ' About to HIDE dialog ghDlgPage(Result + 1),
                           CONTROL SEND CBHNDL, %IDC_SYSTAB, %WM_SETFONT, ghfont1, 0
                           DIALOG SHOW STATE ghTabDlg(Result), %SW_HIDE
      
                       CASE %TCN_SELCHANGE   ' The page is changing
                           ' About to SHOW dialog ghDlgPage(Result + 1)
                           CONTROL SEND CBHNDL, %IDC_SYSTAB, %WM_SETFONT, ghfont, 0
                           DIALOG SHOW STATE ghTabDlg(Result), %SW_SHOW
                       END SELECT
      
                   ' Is it a tooltip message?
                   ELSEIF @pNMHDR.Code = %TTN_NEEDTEXT THEN
                       ' Tooltip text needed, so find out which tab we are on
                       pTT = CBLPARAM
                       Result = @pTT.hdr.idFrom + 1
                       IF Result > 0 THEN
                           szText = $SPC + READ$(Result) + $SPC
                           @pTT.lpszText = VARPTR(szText)
                           FUNCTION = 1
                       END IF
                   END IF
      
              CASE %WM_COMMAND
          END SELECT
      END FUNCTION
      '-------------------------------------------------------
      CALLBACK FUNCTION PORTCallback () AS LONG
      
          SELECT CASE CBMSG
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CBCTL
      
              END SELECT
          END SELECT
      END FUNCTION
      '--------------------------------------------------------------------------------------
      CALLBACK FUNCTION ShowPORTProc()
      
          SELECT CASE AS LONG CBMSG
              CASE %WM_INITDIALOG
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CBCTL
      
                  END SELECT
          END SELECT
      END FUNCTION
      '--------------------------------------------------------------------------------------
      
      FUNCTION ShowPORT(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW hParent, "PORT", 0, 17, 281, 35, %WS_CHILD OR %WS_VISIBLE OR %DS_CONTROL OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
              %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CONTROLPARENT, TO hDlg
          CONTROL ADD LABEL,   hDlg, %IDC_PORT_LAB, "PORT TEST", 15, 5, 250, 20
          CONTROL SEND hDlg, %IDC_PORT_LAB, %WM_SETFONT, ghFont, 0
          ghTabDlg(%dlgPORT) = hdlg
          DIALOG  SET COLOR    hDlg, -1, %color_PORT
      
          DIALOG SHOW STATE hDlg, %SW_HIDE
          DIALOG SHOW MODELESS hDlg CALL PORTCallback
          FUNCTION = lRslt
      END FUNCTION
      '--------------------------------------------------------------------------------------
      CALLBACK FUNCTION STBDCallback () AS LONG
      
          SELECT CASE CBMSG
      
              CASE %WM_COMMAND
                  SELECT CASE AS LONG CBCTL
      
              END SELECT
          END SELECT
      END FUNCTION
      '-----------------------------------------------------------------------
      FUNCTION ShowSTBD(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
          LOCAL hDlg   AS DWORD
      
          DIALOG NEW hParent, "STBD", 0, 17, 281, 35, %WS_CHILD OR %WS_VISIBLE OR %DS_CONTROL OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
              %DS_SETFONT, %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR OR %WS_EX_CONTROLPARENT, TO hDlg
      
          CONTROL ADD LABEL,   hDlg, %IDC_STBD_LAB, "STBD TEST", 15, 5, 250, 20
          CONTROL SEND hDlg, %IDC_STBD_LAB, %WM_SETFONT, ghFont, 0
          ghTabDlg(%dlgSTBD) = hdlg
          DIALOG  SET COLOR    hDlg, -1, %color_STBD
          DIALOG SHOW STATE hdlg, %SW_HIDE
          DIALOG SHOW MODELESS hDlg CALL STBDCallback
          FUNCTION = lRslt
      END FUNCTION
      
      '----------------------------------------------------------------------
      FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
          LOCAL lRslt AS LONG
      
          LOCAL hDlg  AS DWORD
      
          DIALOG NEW hParent, "TAB FONT PROBLEM", 0, 0, 281, 50, %WS_POPUP OR %WS_CAPTION OR _
              %WS_SYSMENU OR %WS_VISIBLE OR %DS_CENTER  OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _
              %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
          CONTROL ADD "SysTabControl32", hDlg, %IDC_SYSTAB, "", 0, 5, 281, 112, %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _
              %WS_CLIPSIBLINGS OR %TCS_TABS OR %TCS_FIXEDWIDTH OR %TCS_FOCUSONBUTTONDOWN OR %TCS_SINGLELINE OR %TCS_RIGHTJUSTIFY, _
              %WS_EX_LEFT OR %WS_EX_LTRREADING
          showSTBD(hdlg)
          showPORT(hdlg)
      
          DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
      
          deleteobject ghfont
          deleteobject ghfont1
          FUNCTION = lRslt
      END FUNCTION
      
      '==================================================================================================================================
      FUNCTION PBMAIN()
          iNITcOMMONcONTROLS
          REDIM ghTabDlg(0 TO 1) AS GLOBAL LONG
          ghFont = MakeFont("Courier New", 12, "")
          ghFont1 = MakeFont("Courier New", 10, "i")
      
          ShowDIALOG1 %HWND_DESKTOP
      END FUNCTION

      Comment


      • #4
        Chris,

        Tested your demo code, and the font works fine on my WinXP Pro box. I don't have any suggestions at this time as to what it might be on your system.

        Regards,
        Jules

        Later...
        Ok, I see, after careful examination of your code, you are trying to set two different fonts on the same control, one for each tab. That's the nature of your problem. To answer your original question, yes you will need to ownerdraw your tabs if you want to have different fonts for each tab. As they say on American Idol, "Sorry!"
        Last edited by Jules Marchildon; 3 May 2008, 09:13 AM.
        Best regards
        Jules
        www.rpmarchildon.com

        Comment


        • #5
          Jules,

          Thanks for looking!

          Today I'm looking for solutions, not challenges, so I shall leave it there.

          Comment

          Working...
          X