Solved

Confused about CTabCtrl...

Posted on 2000-03-24
2
448 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
[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
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

726 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