Solved

How can I add controls into a tab control?

Posted on 1998-09-18
1
171 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 76
matchUp  challenge 6 82
Sed question 2 139
Authenticate using sesu from script 7 159
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

734 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