Announcement

Collapse
No announcement yet.

CONTROL ADD TAB and %TCS_MULTILINE

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

  • CONTROL ADD TAB and %TCS_MULTILINE

    It isn't mentioned in the help file, but since the value is only OR'd to others, I would assume PB passes this value onto the API call it makes to add the TAB .. assuming it is just a wrapper for the SYSTABCONTROL32 function. But I can't get a multiline tab from it even when I use all the same stles that do work with control add "systabcontrol32".

    The other PB9 Tab functions are easier to use than how it is done with systabcontol32, so I'd rather do it with CONTROL ADD TAB. If anyone has this working I'd appreciate an example.
    Barry

  • #2
    Adding %TCS_MULTILINE to the Control Add Tab statement doesn't produce multiline tabs but this does..'
    Code:
    SetWindowLong hCtrl, %GWL_STYLE, (GetWindowLong (hCtrl,%GWL_STYLE) OR %TCS_MULTILINE)
    - except the second line of tabs is obscured - seems the TAB PAGE sizes need to be adjusted..!

    This copy of the PBWin90 TabControl.bas sample has been modified to compensate and seems to do the job,
    thanks to some code posted by Nick Melnick
    You shouldn't have to do this though. It does negate to some extent, the ease of use of the new Tab functions.
    I'll send it in to PB support for their comments.
    Code:
    '==============================================================================
    '
    '  TABCONTROL.BAS example for PowerBASIC for Windows
    '  Copyright (c) 2008 PowerBASIC, Inc.
    '  All Rights Reserved.
    '
    '  Small DDT demonstration of a Tab control.
    '
    '==============================================================================
     
    #COMPILER PBWIN 9
    #COMPILE EXE
    #DIM ALL
     
    ' Contains the XP Manifest file to give the
    ' application the XP look and feel
    #RESOURCE "TabControl.pbr"
     
    #INCLUDE "win32api.inc"
    #INCLUDE "CommCtrl.inc"               ' Need some equates and Functions not built in to PBWin90
                                          ' %TCS_MULTILINE isn't built in - for a reason?? :)
    ' 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
    %AC_RETURN         = 2001
    %AC_TAB            = 2002
     
    GLOBAL hDlg AS LONG
    '------------------/
     
    FUNCTION PBMAIN () AS LONG
      LOCAL hTab1     AS LONG
      LOCAL hTab2     AS LONG
      LOCAL hTab3     AS LONG
      LOCAL hTab4     AS LONG'
      LOCAL hTab5     AS LONG'
      LOCAL hTab6     AS LONG'
      LOCAL hTab7     AS LONG'
      LOCAL hBoldFont AS LONG
     
        LOCAL hAccel    AS DWORD            ' Part of fix for keyboard TABBING behaviour
        DIM AccelTbl(1) AS ACCELAPI         ' dim array of 'ACCELAPI' type
     
        AccelTbl(0).FVIRT   = %FVIRTKEY     ' flag indicates key member specifies a virtual-key code
        AccelTbl(0).KEY     = %VK_RETURN    ' virtual key code (could be ASCII Char code, see FVIRT)
        AccelTbl(0).CMD     = %AC_RETURN    ' accelerator ID for %WM_COMMAND / CBCTL {LOWRD(WPARAM)} msg
     
        AccelTbl(1).FVIRT   = %FVIRTKEY
        AccelTbl(1).KEY     = %VK_TAB
        AccelTbl(1).CMD     = %AC_TAB
     
      ' Create the font used by some controls in this example
      FONT NEW "Arial", 10, 1 TO hBoldFont
     
      DIALOG NEW 0, "Tab Control Example", , , 300, 160, %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, 170, 138    ' original width 298
      ' Enable keyboard cues
      CONTROL SEND hDlg, %ID_TAB, %WM_UPDATEUISTATE, MAKLNG(%UIS_CLEAR, %UISF_HIDEFOCUS OR %UISF_HIDEACCEL), 0
     
      ' 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 SET COLOR    hTab1, %ID_TAB1_LBFIRST, %WHITE, -2
      CONTROL SET FONT     hTab1, %ID_TAB1_LBFIRST, hBoldFont
      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 SET COLOR    hTab1, %ID_TAB1_LBLAST, %WHITE, -2
      CONTROL SET FONT     hTab1, %ID_TAB1_LBLAST, hBoldFont
      CONTROL ADD TEXTBOX, hTab1, %ID_TAB1_TBLAST, "", 60, 20, 100, 12
     
      CONTROL ADD BUTTON,  hTab1, %ID_TAB1_BNSUBMIT, "Submit", 60, 90, 50, 14     ' orig 235, 100, 50, 14
      CONTROL SET FONT     hTab1, %ID_TAB1_BNSUBMIT, hBoldFont
     
      ' 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
      CONTROL SET COLOR     hTab2, %ID_TAB2_CBCHOICES, %BLACK, %GREEN
      CONTROL SET FONT      hTab2, %ID_TAB2_CBCHOICES, hBoldFont
      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
      CONTROL SET COLOR     hTab3, %ID_TAB3_LBCHOICES, %WHITE, %RED
      CONTROL SET FONT      hTab3, %ID_TAB3_LBCHOICES, hBoldFont
      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
      CONTROL SET COLOR     hTab3, %ID_TAB3_TEXTBOX, %WHITE, %RED
      CONTROL SET FONT      hTab3, %ID_TAB3_TEXTBOX, hBoldFont
     
      ' Additional tabs for test
      TAB INSERT PAGE hDlg, %ID_TAB, 4, 0, "Tab 4", CALL TabProc TO hTab4
      TAB INSERT PAGE hDlg, %ID_TAB, 5, 0, "Tab 5", CALL TabProc TO hTab5
      TAB INSERT PAGE hDlg, %ID_TAB, 6, 0, "Tab 6", CALL TabProc TO hTab6
      TAB INSERT PAGE hDlg, %ID_TAB, 7, 0, "Tab 7", CALL TabProc TO hTab7
     
       ACCEL ATTACH hDlg, AccelTbl() TO hAccel          ' <<- Added for TABBING fix
       ' Display the main dialog box
      DIALOG SHOW MODAL hDlg, CALL DlgProc              ' <<- ADDED Call DlgProc
     
      FONT END hBoldFont
     
    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
                ? "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
    '------------------/TabProc
     ' New callback to handle keyboard TABBING (accelerator keys) and Tab Page resizing for Multiline Tabs.
    CALLBACK FUNCTION DlgProc()
     LOCAL cTab, hTC AS LONG
     STATIC hCtrl AS DWORD
     LOCAL r AS Rect
     LOCAL hTab1 AS DWORD
     LOCAL nTab, n AS LONG
     DIM hTab() AS DWORD
     
      SELECT CASE AS LONG CB.MSG
        CASE %WM_INITDIALOG
          SetFocus GetDlgItem(CB.HNDL, %ID_TAB)
          CONTROL HANDLE hDlg, %ID_TAB TO hCtrl
     
          ' Additional Style for Multiline Tabs
          SetWindowLong hCtrl, %GWL_STYLE, (GetWindowLong (hCtrl,%GWL_STYLE) OR %TCS_MULTILINE)
          PlaceTabPageDlg(hDlg, %ID_TAB, r)                   ' Get new page sizes to suit multiline tabs
     
          TAB GET COUNT hDlg, %ID_TAB TO nTab                 ' Apply new page sizes
          REDIM hTab(1 To nTab)
          FOR n = 1 TO nTab
            TAB GET DIALOG hDlg, %ID_TAB, n TO hTab(n)
            MoveWindow hTab(n), r.nLeft, r.nTop, r.nRight, r.nBottom, %FALSE
          NEXT
     
        CASE %WM_COMMAND
          SELECT CASE AS LONG CB.CTL
            CASE %AC_TAB                                                      ' Accelerator key msg
              SELECT CASE GetDlgCtrlID(GetFocus)
                CASE %ID_TAB                                                  ' focus is on the Tab control
                  TAB GET SELECT CBHNDL, %ID_TAB TO cTab
                  TAB GET DIALOG CBHNDL, %ID_TAB, cTab TO hTC                 ' handle of current tab page
                  SetFocus (hTC)
                  EXIT FUNCTION
     
                CASE %ID_TAB1_BNSUBMIT, %ID_TAB2_CBCHOICES, %ID_TAB3_TEXTBOX  ' = last in TAB Order on this Tab page
                  SetFocus GetDlgItem(CB.HNDL, %ID_TAB)                       ' set focus to Tab control
                  EXIT FUNCTION
     
                CASE ELSE
                 SetFocus GetNextDlgTabItem (GetParent(GetFocus), GetFocus, %False)
              END SELECT
     
            CASE %AC_RETURN
              IF GetDlgCtrlID(GetFocus) = %ID_TAB1_BNSUBMIT THEN
                KeyBd_Event %VK_Space, 0, 0, 0: SLEEP 1
                KeyBd_Event %VK_Space, 0, %KEYEVENTF_KEYUP, 0: SLEEP 1
                EXIT FUNCTION
              END IF
              SetFocus GetNextDlgTabItem (GetParent(GetFocus), GetFocus, %False)
          END SELECT
     
      END SELECT
    END FUNCTION
    '------------------/DlgProc
     
    SUB PlaceTabPageDlg(BYVAL hDlg AS DWORD, BYVAL TabCtlID AS LONG, r AS RECT)
       ' Nick Melnick [URL]http://www.powerbasic.com/support/fo...ML/002681.html[/URL]
       ' Returns new x position, new y position, new width and height in r
       LOCAL hTab AS DWORD, x AS LONG, y AS LONG
       LOCAL rc AS RECT
     
       hTab = GetDlgItem(hDlg, TabCtlID)               ' Get handle of Tab Control
       GetWindowRect hTab, BYVAL VARPTR(r)             ' Get its size in screen coordinates
       rc = r
       SendMessage hTab, %TCM_ADJUSTRECT, %FALSE, BYVAL VARPTR(rc)   ' Get size of tab control's DISPLAY AREA
     
       ' r.nLeft & r.nTop are set to the page dialog's new x & y position, wrt the (Tab Control) parent.
       ' Will center your page dialog within the tab control's display area.
       ' r.nRight & r.nBottom are set to the page dialog's new width & height, respectively.
       ' This is the size that the tab control would like your page dialog to be.
       ' Result is in pixels.
       SetRect r, rc.nLeft - r.nLeft, rc.nTop - r.nTop, rc.nright - rc.nleft, rc.nbottom -rc.ntop
     
    END SUB
    '------------------/PlaceTabPageDlg
     
    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 
    '------------------/DrawGradient
    Last edited by Dave Biggs; 5 Dec 2008, 07:40 AM. Reason: Modified Sub PlaceTabPageDlg (removed MapWindowPoints adjustments)
    Rgds, Dave

    Comment


    • #3
      except the second line of tabs is obscured - seems the TAB PAGE sizes need to be adjusted..!
      ......
      I'll send it in to PB support for their comments.
      "As documented, the TCS_MULTILINE STYLE is not supported?"
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Dave,
        Thanks for the routine. It does seem to do the job.

        Michael:
        Where does it say it is documented that it is not supported? It is not mentioned in the docs for CONTROL ADD TAB. It is obvious not to be recognized as it is not in the compiler (only in ComCtrl.inc) and the IDE does not recognize it, either. I can understand if you have mulitlines of 2, 3, 4 or more, that the TAB INSERT PAGE may have trouble.. especially since those can be added before the extra pages, but they seem to be fine in the example Dave gave.
        Barry

        Comment


        • #5
          "As documented, the TCS_MULTILINE STYLE is not supported?"
          I think MCM's guessed reply was a little tongue-in-cheek.

          Jeff's actual reply was:
          The keyboard tabbing will be fixed in an upcoming service release.
          Sorry, but I do not have a date.

          The multi-line style is not compatible with a DDT tab control. I have
          logged your request, but for multi-line tab controls you will need to
          use the API and not DDT.
          (The request was that this style be supported in a future release).
          Empiricaly a mixture of DDT and API does seem to 'deliver', in PBWin90, in this situation. (Caveat emptor as usual )
          Rgds, Dave

          Comment


          • #6
            I did have to modify the fix from Nick Melnick as the pages were over to the right slightly. I had to subract 5 pixels from the r.nleft final value. That had to do with the exact styles I am using.

            Showing that it is possible to do this multiline with the DDT items, I would think all of this could be stuck into PBWin with no problem. Bob does do wonderful things with his compiler. I just wish PB Forms was updated for ListView and TAB controls.
            Barry

            Comment


            • #7
              I just wish PB Forms was updated for ListView and TAB controls.
              Have you sent in a New Feature Suggestion(NFS)?
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                Barry,
                ..I had to subract 5 pixels from the r.nleft final value.
                I have tweaked Nick's Sub in the sample code above - removed the MapWindowPoints adjustments which aren't needed. You might want to try the same in your code.

                I too am eagerly awaiting the next version of PBForms!
                Rgds, Dave

                Comment


                • #9
                  > think MCM's guessed reply was a little tongue-in-cheek.
                  Jeff's actual reply was:
                  ...The multi-line style is not compatible with a DDT tab control.
                  "Not compatible with" sure sounds a lot like "not supported," just as "issue" sure sounds a lot like "bug" and "respiratory and cardiac arrest" sounds a lot like, "dead."

                  However, IMO this disclaimer should be in the help file as an annotation to the "style otions" for the DDT-style tab control.

                  MCM
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    WHo has the copyright on MCM? We buy parts from MCM Electronics, but if I were to make a bet with my 401k I would bet you've been around longer than them.. Wait, I can't bet my 401k. Like Jay Leno said, "I saw my 401k on my mile carton"
                    Barry

                    Comment

                    Working...
                    X