Solved

How can I add controls into a tab control?

Posted on 1998-09-18
1
164 Views
Last Modified: 2013-11-19
I would like to add controls inside a tab control, preferably using the resource editor. How must it be done?

Thanks in advance
fug
0
Comment
Question by:fug
1 Comment
 
LVL 1

Accepted Solution

by:
girts063098 earned 70 total points
Comment Utility
At first, in VC++ manipulate with TabCtrl is not so easy as in VB. In VC objects in TabCtrl are not grouped. It means every object must be set visible or not seperatly.
Here is example how to do it:
(In parenthesis I put the names I used in Example.)
At first you must create TabCtrl(IDC_TAB2) and some objects(IDC_BUTTON3, IDC_BUTTON4, IDC_BUTTON5, IDC_BUTTON6) in Dialog Box.
Then add a member variable to TabCtrl(m_Tab).
Then you must add some initial lines in OnInitialUpdate method in View class:

  TC_ITEM MyTab;
  MyTab.mask = TCIF_TEXT;

  MyTab.pszText = "Selection 1";
  m_Tab.InsertItem(0, &MyTab);

  MyTab.pszText = "Text";
  m_Tab.InsertItem(1, &MyTab);

  MyTab.pszText = "Hmmm...";
  m_Tab.InsertItem(2, &MyTab);

This will create three tabs named: Selection1, Text, Hmmm...

Then you must override ON_IDC_TAB2:TCN_SELCHANGE - OnSelchangeTab:

  int Item0[] = {IDC_BUTTON3, 0};
  int Item1[] = {IDC_BUTTON4, 0};
  int Item2[] = {IDC_BUTTON5, IDC_BUTTON6, 0};
  int * Items[] = {Item0, Item1, Item2, 0 };
  int * pItem, **pItems;
  int nSel = m_Tab.GetCurSel();
  CWnd * pWnd;
  for (pItems = (int **)Items; *pItems; *pItems++)
  for (pItem = *pItems; *pItem; pItem++)
  {
    pWnd = GetDlgItem(*pItem);
    pWnd->ShowWindow(SW_HIDE);
  }
  for (pItem = Items[nSel]; *pItem; pItem++)
  {
    pWnd = GetDlgItem(*pItem);
    pWnd->ShowWindow(SW_SHOW);
  }
Theese lines will make visible objects you have listed in
Item0[] and will make invisible all others.
Item0[], Item1[], etc. contain objects that must be visible in each TabCtrl selection. If you have more than three tabs then just make new variables Item3[], Item4[] etc. and list them in *Items[];

That's all.

Girts.

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mac OS 9 (Classic Environment) vs. MacBook Pro OS 10 8 36
has22 challenge 11 70
sumHeights  challenge 17 59
wordmultiple challenge 12 87
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now