Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TabControl Adding Items 1

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
Hello,


Ok, I have a tab control in my application. I have added the tabs. How in the world do I add other controls on to these different tabs?

For example, how do I had a CListBox control that is on tab index 0? I can't find anything online.

Any help is much appreciated.

-Ron


After a while of studying Engineering at PSU you just want to sit down and eat a bowl of cereal. Thats all you really want.
 
nbgoku,

A little off topic, but for each tab you want on your CPropertySheet you need to create a dialog derived from CPropertyPage. Create your dialog and then create a class for it (i.e. CMyPropPage) with CPropertyPage as the base class. Then, in your code(in CMyMainDlg::OnInitDialog()), instantiate an object of type CMyPropPage and add it to you CPropertySheet:
Code:
m_MyPropSheet.AddPage(m_MyPropPage);
Do this for each tab you want on your property sheet. Then you can call DoModal() on your property sheet.

That's the rough version. Hope this gives you a start.
 
A small correction bluecrush:
Code:
m_MyPropSheet.AddPage(m_MyPropPage);
should be
Code:
m_MyPropSheet.AddPage(&m_MyPropPage);
since this function is declared as
Code:
void AddPage( CPropertyPage *pPage );
 
Ok, I am back again =)

Everything working but I have one problem that I could never seem to fix. When I creat new classes there is never an OnInitDialog Function created. When I attempt to create one and call it the program will crash. What gives? I always have to call a function inside the class from another class to do intialization.

-Ron

/**************
Me: When will the project be finished?
Them: What project?
Me: The one you have been working on for the last 3 years!
Them: Ohh, we can't finish it?
Me: Why?
Them: We don't know how to program...
 
Ah, yes...I believe this is the way it works:

When CreateDlg() gets called, the message WM_INITDIALOG is sent and therefore you need to override the handling of this message (that's what OnInitDialog() does).

Open your ClassWizard and select the class in which you need the OnInitDialog function. Make sure that you've selected your dlg class name in the Object ID box as well. Then, in the Messages box, scroll down until you find WM_INITDIALOG. Click on it and then click on the "Add Function" button. Your function will appear in the Member Functions box and if you click on the "Edit Code" button it will take you directly to your brand new CMyDlg::OnInitDialog() function!
 
This thread seems to be the hit of the month... :))))))))

For those, who continue using TabCtrl one more thing you [COLOR=red yellow] HAVE TO DO [/color]:

Add this piece of code to the header of the each tab page class (e.g. [tt]CMyPage1[/tt] class in my example) just where the functions for the message treatment are declared:

Code:
//{{AFX_MSG(CMyPage1)
...
virtual void OnCancel () {};
virtual void OnOK () {};
//}}AFX_MSG

If you don't do that - the whole page will disappear if you press "[tt]Enter[/tt]" when it is active.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top