Announcement

Collapse
No announcement yet.

Problems with color a Tab dialog in PBWIN9.

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

  • Problems with color a Tab dialog in PBWIN9.

    Hello to everybody.
    I have the following problem:
    I want to do one dialogue with vertical tabs using PBWIN 9 and putting color, but until now I could have done it correctly. As they can see in the example that I modify of the forum, i can put color in tabs, but the text no longer appears ....!!!!

    Can somebody assist me with this?
    Does any form to put a different color in each one of the tabs in the dialogue?

    This is the code:

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    #INCLUDE "commCtrl.inc"
    
    ' Control equates
    %ID_TAB            = 1000
    %ID_TAB1_TBFIRST   = 1001
    %ID_TAB1_LBFIRST   = 1002
    %ID_TAB1_LBLAST    = 1003
    %ID_TAB1_TBLAST    = 1004
    %ID_TAB1_BNSUBMIT  = 1005
    %ID_TAB2_CBCHOICES = 1006
    %ID_TAB3_LBCHOICES = 1007
    %ID_TAB3_TEXTBOX   = 1008
    
    GLOBAL hDlg AS LONG
    
    FUNCTION PBMAIN () AS LONG
      LOCAL hTab1     AS LONG
      LOCAL hTab2     AS LONG
      LOCAL hTab3     AS LONG
      DIALOG NEW 0, "Tab Control Example", , , 300, 140, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME 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
    
      ' Add a Tab control to the main dialog box
      CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 298, 138, %TCS_VERTICAL OR %TCS_OWNERDRAWFIXED
    
    
      ' Build the Tab 1 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1", CALL TabProc TO hTab1
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 2, 6, 100, 12
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 60, 6, 100, 12
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 20, 100, 12
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 60, 20, 100, 12
      CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 235, 100, 50, 14
    
      ' Build the Tab 2 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2", CALL TabProc TO hTab2
      CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 2, 6, 100, 40, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 4"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 5"
      COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
    
      ' Build the Tab 3 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3", CALL TabProc TO hTab3
      CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 2, 6, 100, 60
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 5"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 6"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 7"
      CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 120, 6, 100, 12, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
    
      ' Display the main dialog box
      DIALOG SHOW MODAL hDlg CALL tabCtrlProc
    END FUNCTION
    
    ' Callback function used by all Tab dialogs
    CALLBACK FUNCTION TabCtrlProc()
       SELECT CASE AS LONG CB.MSG
          CASE %WM_DRAWITEM 'draw tab item text in different color on select
             IF CB.WPARAM = %ID_Tab THEN colorTab CBHNDL, CBWPARAM, CBLPARAM
       END SELECT
    END FUNCTION
    
    ' Callback function used by all Tab dialogs
    CALLBACK FUNCTION TabProc
      LOCAL i    AS LONG
      LOCAL s    AS STRING
    
      SELECT CASE AS LONG CB.MSG
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
    
            CASE %ID_TAB1_BNSUBMIT
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
              END IF
    
            CASE %ID_TAB2_CBCHOICES
              IF CB.CTLMSG = %CBN_SELCHANGE THEN
                COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                MSGBOX "You selected "+s
              END IF
    
            CASE %ID_TAB3_LBCHOICES
              IF CB.CTLMSG = %LBN_SELCHANGE THEN
                LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
              END IF
          END SELECT
      END SELECT
    END FUNCTION  
    
    SUB colorTab(hDlg AS LONG, wParm AS LONG, lParm AS LONG)
       LOCAL lDISPtr AS DRAWITEMSTRUCT PTR, zCap AS ASCIIZ * 50
       LOCAL ti AS TC_ITEM, TextDrawFlag AS LONG
       LOCAL nColor, hBrush AS LONG
    
       lDisPtr = lparm
       nColor = RGB(150, 190&, 180&)
       hBrush = CreateSolidBrush(nColor)
       SelectObject @lDisptr.hDc, hBrush
    
       @lDisptr.rcItem.nTop = @lDisptr.rcItem.nTop + 4
       IF @lDisPtr.ItemState = %ODS_SELECTED THEN
          SetTextColor @lDisPtr.hDc, %BLUE
          SetBkColor @lDisPtr.hDc, nColor
          FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
       ELSE
          SetTextColor @lDisPtr.hDc, %BLACK
          SetBkColor @lDisPtr.hDc, GetSysColor(%COLOR_3DFACE)
          FillRect @lDisptr.hDc, @lDisptr.rcItem, GetSysColorBrush(%COLOR_3DFACE)
       END IF
    
       ti.mask = %TCIF_TEXT
       ti.pszText = VARPTR(zCap)
       ti.cchTextMax = SIZEOF(zCap)
       CALL TabCtrl_GetItem(GetDlgItem(hDlg, wParm), @lDisptr.itemID, ti)
       DrawText @lDisptr.hDc, zCap, LEN(zCap), @lDisptr.rcItem, %DT_SINGLELINE OR %DT_CENTER
       DeleteObject hBrush
    END SUB
    Many, many thanks for any kind of help.
    Guillermo F. Robirosa
    [email protected]

  • #2
    Vertical tab text seem to be tricky, here's a start with some other mods in it while I was playing with it.

    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "win32api.inc"
    #INCLUDE "commCtrl.inc"
    
    ' Control equates
    %ID_TAB            = 1000
    %ID_TAB1_TBFIRST   = 1001
    %ID_TAB1_LBFIRST   = 1002
    %ID_TAB1_LBLAST    = 1003
    %ID_TAB1_TBLAST    = 1004
    %ID_TAB1_BNSUBMIT  = 1005
    %ID_TAB2_CBCHOICES = 1006
    %ID_TAB3_LBCHOICES = 1007
    %ID_TAB3_TEXTBOX   = 1008
    
    GLOBAL hDlg AS LONG
    
    FUNCTION PBMAIN () AS LONG
      LOCAL hTab1     AS LONG
      LOCAL hTab2     AS LONG
      LOCAL hTab3     AS LONG
      LOCAL hBoldFont AS LONG
    
      ' Create the font used by some controls in this example
     FONT NEW "Arial", 8, 1 TO hBoldFont
    
      DIALOG NEW 0, "Tab Control Example", , , 300, 140, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_CAPTION OR _
        %WS_SYSMENU OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME 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
    
      ' Add a Tab control to the main dialog box
      CONTROL ADD TAB, hDlg, %ID_TAB, "", 1, 1, 298, 138, %WS_CHILD OR %WS_TABSTOP OR %TCS_VERTICAL OR %TCS_OWNERDRAWFIXED
      CONTROL SET FONT hDlg, %ID_TAB,hBoldFont
    
      ' Build the Tab 1 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 1, 0, "Tab 1", CALL TabProc TO hTab1
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBFIRST,  "First name", 2, 6, 100, 12
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBFIRST, "", 60, 6, 100, 12
      CONTROL ADD LABEL,   hTab1, %ID_TAB1_LBLAST,  "Last name", 2, 20, 100, 12
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 60, 20, 100, 12
      CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 200, 100, 50, 14
    
      ' Build the Tab 2 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 2, 0, "Tab 2", CALL TabProc TO hTab2
      CONTROL ADD COMBOBOX, hTab2, %ID_TAB2_CBCHOICES, , 2, 6, 100, 40, %CBS_DROPDOWNLIST OR %WS_TABSTOP OR %WS_CHILD
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 1"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 2"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 3"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 4"
      COMBOBOX ADD          hTab2, %ID_TAB2_CBCHOICES, "Choice 5"
      COMBOBOX SELECT       hTab2, %ID_TAB2_CBCHOICES, 1
    
      ' Build the Tab 3 dialog and it's controls
      TAB INSERT PAGE hDlg, %ID_TAB, 3, 0, "Tab 3", CALL TabProc TO hTab3
      CONTROL ADD LISTBOX,  hTab3, %ID_TAB3_LBCHOICES, , 2, 6, 100, 60
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 1"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 2"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 3"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 4"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 5"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 6"
      LISTBOX ADD           hTab3, %ID_TAB3_LBCHOICES, "Item 7"
      CONTROL ADD TEXTBOX,  hTab3, %ID_TAB3_TEXTBOX, "", 120, 6, 100, 12, %WS_CHILD OR %WS_TABSTOP OR %WS_VISIBLE OR %ES_READONLY
    
      ' Display the main dialog box
      DIALOG SHOW MODAL hDlg CALL MainDlgProc
    
      FONT END hBoldFont
    
    END FUNCTION
    
    CALLBACK FUNCTION MainDlgProc()
      LOCAL i    AS LONG
      LOCAL s    AS STRING
      SELECT CASE AS LONG CB.MSG
        CASE %WM_DRAWITEM 'draw tab item text in different color on select
    
             IF CB.WPARAM = %ID_Tab THEN
                 colorTab CBHNDL, CBWPARAM, CBLPARAM
                FUNCTION = 1
                EXIT FUNCTION
             END IF
        END SELECT
    END FUNCTION
    
    ' Callback function used by all Tab dialogs
    CALLBACK FUNCTION TabProc
      LOCAL hDC  AS LONG
      LOCAL cTab AS LONG
      LOCAL i    AS LONG
      LOCAL s    AS STRING
    
      SELECT CASE AS LONG CB.MSG
    
        CASE %WM_ERASEBKGND
          ' Display each Tab dialog with a differnt gradient background color
          TAB GET SELECT hDlg, %ID_TAB TO cTab
          hDC = CB.WPARAM
          DrawGradient hDC, cTab
          FUNCTION = 1
          EXIT FUNCTION
    
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
    
            CASE %ID_TAB1_BNSUBMIT
              IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
                MSGBOX "Submit button on Tab 1 clicked", %MB_TASKMODAL
              END IF
    
            CASE %ID_TAB2_CBCHOICES
              IF CB.CTLMSG = %CBN_SELCHANGE THEN
                COMBOBOX GET SELECT CB.HNDL, %ID_TAB2_CBCHOICES TO i
                COMBOBOX GET TEXT   CB.HNDL, %ID_TAB2_CBCHOICES, i TO s
                MSGBOX "You selected "+s
              END IF
    
            CASE %ID_TAB3_LBCHOICES
              IF CB.CTLMSG = %LBN_SELCHANGE THEN
                LISTBOX GET SELECT CB.HNDL, %ID_TAB3_LBCHOICES TO i
                LISTBOX GET TEXT   CB.HNDL, %ID_TAB3_LBCHOICES, i TO s
                CONTROL SET TEXT   CB.HNDL, %ID_TAB3_TEXTBOX, s
              END IF
          END SELECT
      END SELECT
    END FUNCTION
    
    SUB colorTab(hDlg AS LONG, wParm AS LONG, lParm AS LONG)
       LOCAL lDisPtr AS DRAWITEMSTRUCT PTR, zCap AS ASCIIZ * 50
       LOCAL ti AS TC_ITEM, TextDrawFlag AS LONG
       LOCAL nColor, hBrush AS LONG
    
       lDisPtr = lparm
    
       nColor = RGB(150, 190&, 180&)
       hBrush = CreateSolidBrush(nColor)
       SelectObject @lDisptr.hDc, hBrush
    '
      @lDisptr.rcItem.nTop = @lDisptr.rcItem.nTop + 4
      @lDisptr.rcItem.nLeft = @lDisptr.rcItem.nLeft + 4
      @lDisptr.rcItem.nBottom = @lDisptr.rcItem.nBottom + 2
      @lDisptr.rcItem.nRight = @lDisptr.rcItem.nRight + 2
    '
    
       IF @lDisPtr.ItemState = %ODS_SELECTED THEN
          SetTextColor @lDisPtr.hDc, %BLUE
          SetBkColor @lDisPtr.hDc, nColor
          FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
       ELSE
          SetTextColor @lDisPtr.hDc, %BLACK
          SetBkColor @lDisPtr.hDc, nColor 'GetSysColor(%COLOR_3DFACE)
          FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
       END IF
    
       ti.mask = %TCIF_TEXT
       ti.pszText = VARPTR(zCap)
       ti.cchTextMax = SIZEOF(zCap)
       CALL TabCtrl_GetItem(GetDlgItem(hDlg, wParm), @lDisptr.itemID, ti)
       DrawText @lDisptr.hDc, zCap, LEN(zCap), @lDisptr.rcItem, %DT_SINGLELINE OR %DT_LEFT OR %DT_BOTTOM
       DeleteObject hBrush
    END SUB
    '-----------------------------------------------------------------------
    SUB DrawGradient (BYVAL hDC AS DWORD, BYVAL p AS LONG)
      LOCAL rectFill AS RECT
      LOCAL rectClient AS RECT
      LOCAL fStep AS SINGLE
      LOCAL hBrush AS DWORD
      LOCAL lOnBand AS LONG
    
      GetClientRect WindowFromDC(hDC), rectClient
      fStep = rectClient.nbottom / 200
    
      FOR lOnBand = 0 TO 199
        SetRect rectFill, 0, lOnBand * fStep, rectClient.nright + 1, (lOnBand + 1) * fStep
    
        SELECT CASE p
          CASE 1
            hBrush = CreateSolidBrush(RGB(0, 0, 255 - lOnBand))
          CASE 2
            hBrush = CreateSolidBrush(RGB(0, 255 - lOnBand, 0))
          CASE ELSE
            hBrush = CreateSolidBrush(RGB(255 - lOnBand, 0, 0))
        END SELECT
    
        Fillrect hDC, rectFill, hBrush
        DeleteObject hBrush
      NEXT
    
    END SUB
    Rick Angell

    Comment


    • #3
      To change the colour of the Tabs only make these changes in SUB colorTab..
      Code:
         lDisPtr = lparm
       
         Select Case @lDisPtr.ItemId
          Case 0
            nColor = RGB(150, 190, 255)
          Case 1
            nColor = RGB(150, 255, 180)
          Case 2
            nColor = RGB(255, 190, 180)
         End Select
         'nColor = RGB(150, 190&, 180&)
         hBrush = CreateSolidBrush(nColor)
      Rgds, Dave

      Comment


      • #4
        Guillermo,

        Replace the colorTAB SUBroutine with this new one, which includes Dave's addition, and I think you will see a resul more like what you may have had in mind. Someone who has spent more time with vertical tabs may be able to shed some light on why the tab rectangle must be altered before placing the text, but this does the trick. Basically though when text is rotated, the text string's origin has to be accommodated, so we fudge the rectangle here

        Code:
        SUB colorTab(hDlg AS LONG, wParm AS LONG, lParm AS LONG)
           LOCAL lDisPtr AS DRAWITEMSTRUCT PTR, zCap AS ASCIIZ * 50
           LOCAL ti AS TC_ITEM, TextDrawFlag AS LONG
           LOCAL nColor, hBrush AS LONG
        
           lDisPtr = lParm
        
           SELECT CASE @lDisPtr.ItemId
            CASE 0
              nColor = RGB(150, 190, 255)
            CASE 1
              nColor = RGB(150, 255, 180)
            CASE 2
              nColor = RGB(255, 190, 180)
           END SELECT
        
           hBrush = CreateSolidBrush(nColor)
           
           SelectObject @lDisptr.hDc, hBrush
        '
           IF @lDisPtr.ItemState = %ODS_SELECTED THEN
              SetTextColor @lDisPtr.hDc, %BLUE
              SetBkColor @lDisPtr.hDc, nColor
              FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
           ELSE
              SetTextColor @lDisPtr.hDc, %BLACK
              SetBkColor @lDisPtr.hDc, nColor 'GetSysColor(%COLOR_3DFACE)
              FillRect @lDisptr.hDc, @lDisptr.rcItem, hBrush
           END IF
        
           ti.mask = %TCIF_TEXT
           ti.pszText = VARPTR(zCap)
           ti.cchTextMax = SIZEOF(zCap)
           CALL TabCtrl_GetItem(GetDlgItem(hDlg, wParm), @lDisptr.itemID, ti)
           @lDisptr.rcItem.nLeft = @lDisptr.rcItem.nLeft + 4
           @lDisptr.rcItem.nBottom = @lDisptr.rcItem.nBottom + 8
           DrawText @lDisptr.hDc, zCap, LEN(zCap), @lDisptr.rcItem, %DT_SINGLELINE OR %DT_LEFT OR _
            %DT_BOTTOM OR %DT_NOCLIP OR %DT_NOPREFIX OR %DT_EXTERNALLEADING
           DeleteObject hBrush
        END SUB
        Rick Angell

        Comment


        • #5
          Let's see now.

          At 5pm (local time) A guy in Argentina posts a question with a relevant snippet of code.

          At 11pm a guy in (Well, we don't know where in the world he is. Probably an uncover guy working for PB's KAOS, maybe in a cave in Afghanistan) posts working code to show how to answer the question.

          At 12PM a guy in the far reaches of Australia posts a snippet showing the guy in Argentina how to make his code work.

          At 10am a guy in the East Coast of the US just sits back and marvels.

          Ain't life in PB_Land grand?
          It's a pretty day. I hope you enjoy it.

          Gösta

          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

          Comment


          • #6
            A cave might be a cheaper digs, especially if it a gold vein to mine in my spre time, but it'd be in the Americas ....
            Rick Angell

            Comment

            Working...
            X