BCX_TAB function

Purpose:

BCX_TAB creates a tab control.

Syntax:

hCtl = BCX_TAB(hwndParent AS HWND, _
                 CtlID AS INTEGER, _
              NumPages AS INTEGER, _
                   hArray AS HWND, _
                  Array AS STRING, _
                  Xpos AS INTEGER, _
                  Ypos AS INTEGER, _
                 Width AS INTEGER, _
                Height AS INTEGER, _
         HIMAGELIST AS HIMAGELIST _
           [, WinStyle AS INTEGER] _
         [, ExWinStyle AS INTEGER])

Return Value:

  • Data type: HWND
    hCtl The handle of the new tab control if the function succeeds. If the function fails, the return value is NULL.

Parameters:

  • Data type: HWND
    hwndParent The handle of the parent window of the tab control being created.
  • Data type: INTEGER
    CtlID Control ID. A negative value can be entered as an argument for the CtlID% parameter to indicate that the tab control should not be subclassed. Then, in the message loop, enter:
    CASE WM_NOTIFY
      BCX_TABSELECT
    
    This will work with regular forms and dialogs. Operation of the control will behave as usual when the control id is a positive value.
  • Data type: INTEGER
    NumPages number of Pages/Tabs the Tab Control will have.
  • Data type: HWND
    hArray array of handles returned for each page.
  • Data type: STRING
    Array array of titles for each Page/Tab.
  • Data type: INTEGER
    Xpos initial horizontal position of the tab control being created. Xpos% is the x-coordinate of the upper-left corner of the tab control being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Ypos initial vertical position of the tab control being created. Ypos% is the initial y-coordinate of the upper-left corner of the tab control being created relative to the upper-left corner of the parent window's client area.
  • Data type: INTEGER
    Width width, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels , of the tab control being created.
  • Data type: INTEGER
    Height height, in device units or, if the PIXELS optional parameter was specified in the GUI statement, in pixels , of the tab control being created.
  • HIMAGELIST image list to be placed on each Page/Tab. Enter NULL for none.
  • Data type: INTEGER
    WinStyle [OPTIONAL] replaces the default Window Style; WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS | TCS_TABS | TCS_SINGLELINE | TCS_FOCUSONBUTTONDOWN. For more information, visit the Microsoft Tab Control Styles webpage and the Microsoft Window Styles webpage.
  • Data type: INTEGER
    ExWinStyle [OPTIONAL] replaces the default Extended Window Style, 0. For more information, visit the Microsoft Extended Window Styles webpage.

Example 1:

Here is a complete example using the BCX_TAB function.

 ' *************************************************************
' *  Color_Tab – P.Kort(8 Jan , 2005)                         *
' *  Ver : 0.0.0.1                                            *
' *  BCX_Tab Control Example                                  *
' *************************************************************

 GUI "Color_Tab"
 
 GLOBAL ghMainFrm AS CONTROL
 GLOBAL ghMainTab AS CONTROL
 GLOBAL ghTab[3] AS HWND
 
 SET gTabPage$[3]
   "Page 1", "Page 2", "Page 3"
 END SET
 
 MACRO ID_TAB     = 500
 MACRO ID_LABEL1  = 501
 MACRO ID_BUTTON1 = 502
 MACRO ID_BUTTON2 = 503
 
 '================================================================
SUB FORMLOAD()
 
   ghMainFrm = BCX_FORM("BCX Color Tab Demo", 0, 0, 0, 0)
 
   ghMainTab = BCX_TAB(ghMainFrm, ID_TAB, 3, ghTab, gTabPage$, 0, 0, 400, 250)
 
   BCX_LABEL("This is a Label", ghTab[0], ID_LABEL1, 20, 25, 60, 10)
   BCX_BUTTON("Button 1", ghTab[1], ID_BUTTON1, 20, 25, 60, 20)
   BCX_BUTTON("Button 2", ghTab[2], ID_BUTTON2, 20, 25, 40, 15)
 
   BCX_SET_FORM_COLOR(ghTab[0], QBCOLOR(1))
 
   'Generate a WM_SIZE message
   MoveWindow(ghMainFrm, 0, 0, 500, 400, TRUE) 'Force a WM_SIZE
 
   CENTER(ghMainFrm)
   SHOW(ghMainFrm)
 
   SetFocus(ghMainTab)
 
 END SUB
 
 '================================================================

 BEGIN EVENTS
   SELECT CASE CBMSG
 
   CASE WM_SIZE
     STATIC cxClient%
     STATIC cyClient%
 
     cxClient=LOWORD(lParam)
     cyClient=HIWORD(lParam)
 
     MoveWindow(ghMainTab, 2, 2, cxClient - 4, cyClient - 2, TRUE)
     EXIT FUNCTION
 
   CASE WM_NOTIFY
     DIM  ptnmhdr AS NMHDR*
     DIM  PageNo  AS LONG
     
     ptnmhdr = (NMHDR*)lParam
 
     IF ptnmhdr->code >= TCN_LAST && ptnmhdr->code <= TCN_FIRST THEN
       SELECT CASE ptnmhdr->idFrom
       CASE ID_TAB
         SELECT CASE ptnmhdr->code
         CASE TCN_SELCHANGE
           PageNo = SendMessage(GetDlgItem(hWnd, (UINT)ID_TAB), _
           (WPARAM)TCM_GETCURSEL, (LPARAM)0, 0)
           ShowWindow(ghTab[PageNo], SW_SHOW)
 
           SELECT CASE PageNo
           CASE 0
             BCX_SET_FORM_COLOR(ghTab[0], QBCOLOR(1))
             EXIT FUNCTION
 
           CASE 1
             BCX_SET_FORM_COLOR(ghTab[1], QBCOLOR(3))
             EXIT FUNCTION
 
           CASE 2
             BCX_SET_FORM_COLOR(ghTab[2], QBCOLOR(15))
             EXIT FUNCTION
 
           END SELECT
         END SELECT
       END SELECT
     END IF
 
   CASE WM_CLOSE
     DestroyWindow(hWnd)
     EXIT FUNCTION
 
   CASE WM_DESTROY
     PostQuitMessage(0)
     EXIT FUNCTION
 
   END SELECT
 END EVENTS

BCX_REMTAB statement

Purpose:

BCX_REMTAB removes a specified tab from a tab control.

Syntax:

BCX_REMTAB(hTabControl AS HWND, _
     TheTabToRemove AS INTEGER)

Parameters:

  • Data type: HWND
    hTabControl The handle of the tab control in which the tab is to be removed.
  • Data type: INTEGER
    TheTabToRemove Index, zero-based, to the tab to be removed.

BCX_ADDTAB statement

Purpose:

BCX_ADDTAB adds a specified tab to a tab control.

Syntax:

BCX_ADDTAB(hTabControl AS HWND, _
        TheTabToAdd AS INTEGER, _
             TabText AS STRING _
      [, ImageIndex AS INTEGER] _
     [, ShowHideTab AS INTEGER])

Parameters:

  • Data type: HWND
    hTabControl The handle of the tab control in which the tab is to be added.
  • Data type: INTEGER
    TheTabToAdd Index, zero-based, to the tab to be added.
  • Data type: STRING
    TabText Text string to be displayed on tab.
  • Data type: INTEGER
    ImageIndex [OPTIONAL] Integer specifying the index of an image in the tab control's image list.
  • Data type: INTEGER
    ShowHideTab [OPTIONAL] Integer 0 specifies that tab is hidden, 1(default) specifies that tab is shown.

BCX_TABSELECT statement

Purpose:

BCX_TABSELECT is only used with BCX_TAB. BCX_TABSELECT was made available to allow using BCX_TAB within a dialog box, although it also can be used with a BCX_FORM

When calling BCX_TAB, a negative value can be entered as an argument for the CtlID% parameter(see above BCX_TAB function parameter description) to indicate that the tab control should not be subclassed. Then, in the message loop, enter:

CASE WM_NOTIFY
  BCX_TABSELECT

This will handle the switching between BCX_TAB pages.

Syntax:

BCX_TABSELECT

Parameters:

  • No parameters

Example 2:

The following demonstrates usage of the BCX_TAB, BCX_ADDTAB, BCX_REMTAB and BCX_TABSELECT procedures.

GUI "TabTest", PIXELS

GLOBAL Form1 AS HWND

SUB FORMLOAD
  Form1 = BCX_FORM("Tab Test", 0, 0, 640, 480)
  BCX_BUTTON("Tab Dialog", Form1, 1000, 10, 10)
  CENTER(Form1)
  SHOW(Form1)
END SUB


BEGIN EVENTS
  SELECT CASE CBMSG
  CASE WM_COMMAND
    SELECT CASE CBCTL
    CASE 1000
      BCX_MDIALOG(Configure, "Test Tab", Form1, 60, _
      30, 325, 230, 0, 0, "ms sans serif", 8)
    END SELECT
  END SELECT
END EVENTS


BEGIN MODAL DIALOG AS Configure
  STATIC Tabpages[32] AS HWND
  STATIC Tab1 AS HWND

  SHAREDSET Tablabels$[]
    "Page 1", "Page 2", "Page 3", "Page 4"
  END SET

  SELECT CASE CBMSG

  CASE WM_INITDIALOG
    Tab1 = BCX_TAB(hWnd, -300, 4, Tabpages, Tablabels$, 1, 5, 324, 198)
    BCX_BUTTON("Add Tab", hWnd, 90, 200 , 210)
    BCX_BUTTON("Remove Tab", hWnd, 100, 260 , 210)

    FUNCTION = TRUE

  CASE WM_NOTIFY
    BCX_TABSELECT

  CASE WM_COMMAND
    SELECT CASE CBCTL
    CASE 90
      DIM RAW pn = TabCtrl_GetItemCount(Tab1)
      IF pn = 31 THEN EXIT SELECT
      BCX_ADDTAB(Tab1, pn + 1, "Page" & STR$(pn + 1))

    CASE 100
      DIM RAW cur = TabCtrl_GetCurSel(Tab1)
      IF cur = -1 THEN EXIT SELECT
      BCX_REMTAB(Tab1, cur)
    END SELECT
  END SELECT
END DIALOG