Solved

Confused about CTabCtrl...

Posted on 2000-03-24
2
441 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

772 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

11 Experts available now in Live!

Get 1:1 Help Now