BBC BASIC for Windows
Programming >> User Interface >> Tab control in a dialogue box
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1404922490

Tab control in a dialogue box
Post by JB91 on Jul 9th, 2014, 4:14pm

Hello,

I want to add a tab control to a dialogue box, but I am not quite sure how to do it. I have tried adapting the code found in the "Creating a tab control" in the BB4W wiki, but that doesn't seem to work. sad
Re: Tab control in a dialogue box
Post by rtr on Jul 9th, 2014, 8:42pm

on Jul 9th, 2014, 4:14pm, JB91 wrote:
I want to add a tab control to a dialogue box, but I am not quite sure how to do it.

You will need to specify it in the dialogue template using PROC_dlgctrl() with the class name "SysTabControl32", something like this:

Code:
      PROC_dlgctrl(dlg%, "", id%, x%, y%, cx%, cy%, 0, "SysTabControl32") 

After the dialogue box has been shown you can retrieve the handle of the tab control in the usual way using GetDlgItem. Thereafter you should be able to react to tab changes using code very similar to that in the Wiki.

Richard.
Re: Tab control in a dialogue box
Post by JB91 on Jul 20th, 2014, 12:31pm

I've managed to create the tab control, although the procedure for creating the tabs in the wiki doesn't work.
Re: Tab control in a dialogue box
Post by rtr on Jul 20th, 2014, 2:02pm

on Jul 20th, 2014, 12:31pm, JB91 wrote:
I've managed to create the tab control, although the procedure for creating the tabs in the wiki doesn't work.

Do you mean the TCM_INSERTITEMA message isn't working? I find that surprising; how would the Tab Control 'know' that it's in a dialogue box and therefore behave differently from normal? I would suggest that perhaps the explanation is that you have an error in your code.

Richard.

Re: Tab control in a dialogue box
Post by rtr on Jul 20th, 2014, 3:55pm

on Jul 20th, 2014, 2:02pm, Richard Russell wrote:
Do you mean the TCM_INSERTITEMA message isn't working? I find that surprising

And indeed, when I try it, it seems to work fine. I took the code on the Wiki for creating a tab control, made the bare minimum of changes to create it in a dialogue box (using PROC_dlgctrl as described earlier), and the three tabs appear just as one would expect:

Code:
      INSTALL @lib$+"WINLIB2"

      REM!WC
      ICC_TAB_CLASSES = 8
      TCIF_TEXT = 1
      TCM_INSERTITEMA = 4871
      WS_CHILD = &40000000
      WS_VISIBLE = &10000000

      DIM icex{dwSize%, dwICC%}

      icex.dwSize% = DIM(icex{})
      icex.dwICC% = ICC_TAB_CLASSES
      SYS "InitCommonControlsEx", icex{}

      REM Trapping errors is desirable; otherwise an error
      REM message may be hidden behind the tab control:

      ON ERROR SYS "MessageBox", @hwnd%, REPORT$, 0, 48 : QUIT

      REM You create an 'empty' tab control as follows:

      tcid% = 101
      dlg% = FN_newdialog("Tab Control in Dialogue Box", 0, 0, 300, 250, 8, 1000)
      PROC_dlgctrl(dlg%, "", tcid%, 10, 10, 280, 230, WS_VISIBLE OR WS_CHILD, "SysTabControl32")
      PROC_showdialog(dlg%)
      SYS "GetDlgItem", !dlg%, tcid% TO hTC%
      IF hTC% = 0 ERROR 100, "Couldn't create tab control"

      REM At this stage the control doesn't have any tabs;
      REM to add them use code similar to the following:

      PROCadd_tab(hTC%, "First", 1)
      PROCadd_tab(hTC%, "Second", 2)
      PROCadd_tab(hTC%, "Third", 3)

      REPEAT WAIT 1 : UNTIL FALSE
      END

      DEF PROCadd_tab(htc%, text$, id%)
      LOCAL cti{}, res%
      DIM cti{mask%, dwState%, dwStateMask%, pszText%, cchTextMax%, iImage%, lparam%}
      text$ += CHR$0
      cti.mask% = TCIF_TEXT
      cti.pszText% = !^text$
      SYS "SendMessage", htc%, TCM_INSERTITEMA, id%, cti{} TO res%
      IF res% = -1 ERROR 100, "Couldn't send Tab Control info"
      ENDPROC 

This is so straightforward it's hard to know what might be the problem with your version.

Richard.

Re: Tab control in a dialogue box
Post by JB91 on Jul 21st, 2014, 11:22am

Thanks for your help, Richard. It works now and I've realised what my mistake was! smiley