Solved

Confused about CTabCtrl...

Posted on 2000-03-24
2
445 Views
Last Modified: 2008-02-01
I wanted to ask advice about how to go about something...

I'm creating a dialog that requires tabbed pages.  I have chosen not to use Property Pages, so that I wouldn't spawn another dialog box.  Therefore, I picked CTabCtrl.  Looking at the Microsoft example, FIRE, I noticed that the single control (a picture box) is placed on the dialog (at design time) and shows up regardless of which tab page is showing.  I intend to display several controls per page and wondered how to go about this.  Must all the controls (at design time) sit on the dialog, rather than the tabbed page?  How best can I do this without making a mess?  How should the controls be link, so that they only show when the appropriate page is being displayed?

In VB there is extensive support for design time layout of controls and for grouping of controls (on the tabbed pages).  How best should I go about this in VC?

Thanks
- Don Schindler
0
Comment
Question by:donschin
2 Comments
 

Accepted Solution

by:
vessel earned 50 total points
ID: 2656627
Hi, donschin.

First of all, consider using CPropertyPage and CPropertySheet classes (see MFC samples).

If for some reason you want to place tabbed pages to your dialog manually you should go this way:
- Create your dialog with controls you need and leave space for tabbed pages. Let the class name for your dialog be CYourDialog.
- Prepare pages. Use resource editor to create dialog templates for your pages. See "Using Property Sheets in Your Application" MSDN article in order to specify correct styles for dialog template resource. When you add class for new template use CPropertyPage as a parent class instead of CDialog. So you have CYourPage1, CYourPage2, ...
- Then insert new class CYourSheet inherited from CPropertySheet. Its constructor will be:
CYourSheet::CYourSheet() {
  AddPage(new CYourPage1);
  AddPage(new CYourPage2);
  // ...
}
- Override OnCreate method in CYourDialog and add m_pYourSheet member variable which is a pointer to CYourSheet:
int CYourDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (CDialog::OnCreate(lpCreateStruct) == -1)  return -1;

  m_pYourSheet = new CYourSheet();
  if (!m_pYourSheet->Create(this, WS_CHILD | WS_VISIBLE | DS_CONTROL, 0))  return -1;

  // Resize the dialog so that it fits around your tabbed pages
  // and other controls.
  CRect rectClient;
  m_pYourSheet->GetWindowRect(rectClient);
  CRect rectWindow = rectClient;
  CalcWindowRect(rectWindow);
  SetWindowPos(NULL, rectWindow.left, rectWindow.top,
  rectWindow.Width()/* add extra width here*/,
  rectWindow.Height() + 35, // extra height added
  0);
  // Set position for your tabbed pages - (0, 0)
  m_pYourSheet->SetWindowPos(NULL, 0, 0,
  rectClient.Width(), rectClient.Height(), SWP_NOZORDER | SWP_NOACTIVATE);

  return 0;
}

Note that you needn't to use CTabCtrl.

Note also that it's very important to use DS_CONTROL flag otherwise system crashes. This flag will make CYourSheet behave like a control rather than a dialog box.
0
 

Author Comment

by:donschin
ID: 2662452
Thanks!
I have followed your instructions and found a good reliable method for building the pages...  I built two blank pages and created CPropertyPage based classes for them.  Moved all the code (suggested for OnCreate) to OnInit, and built.  The dialog pops up with two tabs with pages containing static text ("Page 1" and "Page 2").  This works fine!  I need to peruse the CPropertyPage help pages to set the tab text, but that should be easy.

You might consider posting these recommendations as instructions for "Better Tab Controls."  This is really nice...

I must say all the other advice I have received depended on using some other custom control, or some horrendous collection of classes.  This is nice and simple.

Thank VERY much for your attention,

- Don Schindler
P.S.  Next time I'll post my questions to the *right* group (like the MFC group)!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 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