[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Confused about CTabCtrl...

Posted on 2000-03-24
2
Medium Priority
?
451 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

656 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