Solved

How can I add controls into a tab control?

Posted on 1998-09-18
1
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
girts063098 earned 70 total points
ID: 1322263
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

691 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