Archived

This topic is now archived and is closed to further replies.

gavrhen

MFC People where are you at?

Recommended Posts

MFC people I just wanted to know if you knew how to get Tabs to work. I went to codeguru.com and codeproject.com but they didn''t have very good tutorials on how to get tabs to work for begginers. If you don''t know the answer downlaod the source and tell me what you think about the program. I think I''ll make a tut on it if I can ever figure out tabs. STARVIEWMFC

Share this post


Link to post
Share on other sites
As Keanu Reaves(sp) would say...woooh..

Tabs in MFC are tricky. You may want
to check out CTabCtrl at MSDN.
I looked into them earlier. I remember
having to make dialogs for each of the pages
I wanted to add to them. Then I read
to add them manually. I never
got around to trying it out since
it was easier to make a wrapper in VB.
Please post if you find a good resource!
Please!

Share this post


Link to post
Share on other sites
Yeah for what it''s worth, I also looked into them and came to the same conclusions as Taulin. They are a pain in the neck
You have to make one dialog for each tab and combine them all in code.

Its one of those things (there seem to be way too many) that ought to be really easy to do, but isn''t.

That''s my experience anyway.



-ns-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Easy solution is to use FOX. It''s better than MFC and supports multiple platforms too. Using Tabs as wells as other widgets are a piece of cake.

http://www.cfdrc.com/FOX/fox.html

Share this post


Link to post
Share on other sites
Ahhhhhhh tab controls, yes un fun. easy in VB (go figure) and a pain in MFC. I would keep checking on Codeguru.com. I found my examples there. A loose explanation on the one i found is this:

Draw your tab control onto the dialog. Then what you have to do is create seperate dialogs to place upon the dialog (these seperate dialogs will be shown or hidden depending upon which tab is selected).

So then in your main dialog, u have to set up those other dialogs to be displayed in your main dialog (the one with the actual tab control). Here is an example:
First underneath the last include as global we need this:
(inside your main dialog.cpp the one with the tab control on it.)
#include "DlgFirst.h"
#include "DlgSecond.h"
#include "DlgThird.h"


//Instantiate your other dialog classes to here.
DlgFirst dlg_MyFirstDialog;
DlgSecond dlg_MyFirstDialog; //DlgSecond, is the name of your
//second dialog class you made.
DlgThird dlg_MyFirstDialog;


BOOL DlgMain::Create(CWnd*pParent, LPCSTR lpszTitle)
{
//fill out top tab lables
//note the IDC_TAB1 its the id of your tab control
CTabCtrl *tabMain = (CTabCtrl *) GetDlgItem(IDC_TAB1);
tabMain->InsertItem(0, _T("My Tab 1"));
tabMain->InsertItem(1, _T("My Tab 2"));
tabMain->InsertItem(2, _T("My Tab 3"));
//Select our tabs to start
LoadCurrentSel(); //we will return to this.
}

//this is important function, it gets the user clicks
//figures out what tab it was on and then displays the appropiate
//window

void DlgMain::LoadCurrentSel(LPNMHDR *hdr, LPARAM *NotUsed)
{
dlg_MyFirstDialog.ShowWindow(SW_HIDE);
dlg_MySecondDialog.ShowWindow(SW_HIDE);
dlg_MyThirdDialog.ShowWindow(SW_HIDE);
// Get current selection
CTabCtrl *tabMain = (CTabCtrl *) GetDlgItem(IDC_TAB1); //not the IDC TAB1 again
int nCurSel = tabMain->GetCurSel();
// Load corresponding child
switch(nCurSel)
{
case 0:
{
// Show child 1
dlg_MyFirstDialog.ShowWindow(SW_SHOW);
dlg_MyFirstDialog.CenterWindow();
break;
}
case 1:
{
// Show child 2
dlg_MySecondDialog.ShowWindow(SW_SHOW);
dlg_MySecondDialog.CenterWindow();
break;
}
case 2:
{
// Show child 3
dlg_MyThirdDialog.ShowWindow(SW_SHOW);
dlg_MyThirdDialog.CenterWindow();
break;
}
}


}

then down furhter still in your main dialog.cpp (the dialog with the tab control on it)
you will see:

BEGIN_MESSAGE_MAP(DlgMain, CAcUiDockControlBar)
//{{AFX_MSG_MAP(DlgMain)
ON_WM_CREATE()//should already be there
///need to add this:makes sure we call LoadCurrentSel
//when windows gets the TCN_SELCHANGE message.
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, LoadCurrentSel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Then in that main dialog .h the public part of your class u need this:

void LoadCurrentSel(LPNMHDR *hdr = NULL, LPARAM *NotUsed = NULL);



As for the Dialogs you want (basically whats on each tab is a seperate dialog that ive coined above to be DlgFirst, DlgSecond etc..)
These dialogs need to have the following prorperties:

In styles tab of properties make sure the style is:
Child
Border is None
and everythign else in every other styles tab is NOT checked.

Then the cool thing is each "tab" you have info on is a matter of editing and adding controls to the dialog that represents a tab so it should be pretty straight forward. I hope this helps. If not, please email me and maybe I can work with ya on this.

Regards,
Shane
p.s. email is: Codejoy@yahoo.com



Share this post


Link to post
Share on other sites