Link to home
Start Free TrialLog in
Avatar of mfcseeker
mfcseeker

asked on

PropertSheet-PropertyPage

I have created a Tab conrol by using PropertSheet-PropertyPage, so when I execute the program, the first thing that appears are the tab boxes with the options Ok/Cancel/help. If I click on Canel, then the main dialog window appear.
How can I insert the tabs to the main dialog window, so when I run the progam I only get the tabs and if i click cancel, I exit the program.

Avatar of Cheff
Cheff

what kind of app is it? sdi, mdi, dialog and where do u start your initialisation for proppage and propsheet? give some more informations and I'll help you...
> How can I insert the tabs to the main *dialog* window...

I assume your application is dialog based.
So you have to get your dialog into the dialog editor
and add tab control. Also add the buttons you want.
Avatar of mfcseeker

ASKER

The application is dialog.
The intialization for propage and prosheet starts inside
ProjectDlg.cpp inside:  
BOOL CProjectDlg::OnInitDialog()
{
     CDialog::OnInitDialog();



Thank you in advance,
I can still only guess what you did.
Did you do it like this?
You created a variable of you CTabCtrl m_TabCtrl in your dialog class and called in OnInitDialog:

  RECT Rect;
  TC_ITEM tci;

  m_CTabCtrl.GetItemRect( 0, &Rect );

  tci.pszText="Name of Page1";
  m_CTCrtRegister.InsertItem( 0, &tci );

//and fill your Tabctrl with your propertypages:
//(of course, CMyPropPage is public derived from
//CPropertyPage)

  m_MyPropPage.Create( IDD_MYPROPPAGE, &m_CTabCtrl);
  m_MyPropPage.SetWindowPos( 0, Rect.left, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER );

If this wasn't the way you did it, please give some more code of OnInitDialog.

So we will work on it together...
BOOL CProjectOwnDlg::OnInitDialog()
{
     CDialog::OnInitDialog();

     HELLO        HELLOPSheet("My Savings Prop Sheet");

        EQUATION            equationPage;
        PERIODIC            periodicPage;

        HELLOPSheet.AddPage(&equationPage);
        HELLOPSheet.AddPage(&periodicPage);

     HELLOPSheet.DoModal();
What class is HELLO derived from ?
ASKER CERTIFIED SOLUTION
Avatar of aphillips
aphillips
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yehaa, please be kind and don't use your own typedefs or give their definition, now we can guess again what's meant...
so assuming:

typedef CHello HELLO;     //class CHello : public CPropetySheet

typedef CEquation EQUATION; //class CEquation : public CPropertyPage

ok ... now I understand.. yes your code says exactly what you described..  You constructing an extra Dialog with HELLOPSheet and puts your Pages inside...
But that's wrong because CPropertysheet is known as tab dialog boxes.
But what you have to do is another thing.. You have to use your CTabCtrl Element. So use my code given above to put your Pages inside your CTabCtrl. this will do what you want...  please refer MSDN for correct corerect function prototype of SetWindowPos
this isn't a good solution aphillips, cause you if you use CFormView e.g.  you have this problem again..  Use the correct way mfcseeker as I posted..
> this isn't a good solution aphillips, cause you if you use CFormView

What?  This is a dialog based app.  What has a CFormView got to do with it?

The question seems straightforward to me but I will restate it so that this can be confirmed by mfcseeker and so other responders get back on the track.

"I want to create a dialog application but rather than a simple dialog I want one with tabs and multiple pages (ie a tabbed dialog box or in Windows parlance a property sheet).  I want this property sheet to be the main window which, when closed exits the application."
Thank you guys, I appreciate your help. I am going to try each of your codes and post back which will work.

my way isn't the easier one, because you have to programm the OnSelChange. Otherwise it won't react one changing the tab..
but if you know what child and parent windows and creation are and work... then it's easy too read, to access.. I swear on this way because it's much more straight forward in the whole MFC concept... And I don't like to manipulate the code biult by Wizard. If you do something wrong you probably never find the error... However, try and test the two versions.. If you need more help with my code just post again ;)...
Cheff this is what I did:
I created added a Tab Control in the dialog editor and declared a varriable name m_tab, then I went inside the .cpp file and added your code under OnInitDial:
My questions are in comments next to each code:
 
 RECT Rect;
 TC_ITEM tci;

 m_CTabCtrl.GetItemRect( 0, &Rect );  //what do I replace
                                     //CTabCtrl with

 tci.pszText="Name of Page1";
 m_CTCrtRegister.InsertItem( 0, &tci );  //Same here for
                                        //CTCrtRegister


 m_MyPropPage.Create( IDD_MYPROPPAGE, &m_CTabCtrl);
//My property sheet doesn't have a variable so there is nothing to replace m_MyPropPage with.
 m_MyPropPage.SetWindowPos( 0, Rect.left, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
//Same here


Thank you
aphillips

Your code is not easily understood
// #include "ProjectOwnDlg.h"
#include "MyPropertySheet.h"

...

//     CProjectOwnDlg dlg;
//     dlg.DoModal()
    CMyPropertySheet dlg;
    dlg.DoModal();
could you please explain more these steps.
> could you please explain more these steps...
I explained the steps in detail.  What don't you understand?

There is a great deal of confusion in this discussion due, I believe, mainly to the mention of a tab-control when you really were just talking about a property sheet.

Could you just say whether my restatement of your quesyion is correct.  If not please restate your question.

Here is my restatement of your question:
"I want to create a dialog application but rather than a simple dialog I want one with tabs and multiple pages (ie a tabbed dialog box or in Windows parlance a property sheet).  I want this property sheet to be the main window which, when closed exits the application."
This is what you told me and what I have:

1. Create an MFC dialog based app (I think you did this).
Done
2. Create your property sheet (I think you've done this).
Done
3. Replace the use of the dialog that was created with the app with your own property sheet.
//So you are saying, delete the ProjectOwnDlg.h and ProjecrOwnDlg.cpp from the folder, and then put these two statements inside propertysheet.cpp files? is that right?

    CMyPropertySheet dlg;
    dlg.DoModal();

I am going to raise the points for this question, either if the code worked or not, becuase you guys are really trying to help.
@aphillips
I don't want to argue with you... Of course, if it's just a dialog based app your solution is fine and works... But I meant that we should explain such things in general if it is possible. So using CTabCtrl will be the more general way and more reusable code when programming a tabsheet and it will give ppl more understanding about MFC-structures instead of fixing wizard's code. I do only know a few ppl who really understand wizard code in detail and who can change it in a way that it will still work and do what you want...

So I hope this we agree now and you don't worry about me :-) ...(code should be flexible;-))........

Cheff

@mfcseeker
ups.. yeah.. I forgot to change the name.. sorry..
m_CTCrTRegister should be m_CTabCtrl...

ok you have declared m_tab a CTabCtrl variable.. then all positions in my code where m_CTabCtrl is, should be replaced by m_tab...

ok... and then:
m_MyPropPage.Create( IDD_MYPROPPAGE, &m_CTabCtrl);
//My property sheet doesn't have a variable so there is nothing to replace m_MyPropPage with.
m_MyPropPage.SetWindowPos( 0, Rect.left, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER );
//Same here
well, when you have created a propsheet and call the wizard, he asks you to build a class.. choose yes, derived from: CPropertyPage

add a variable of this class to your dialog class... this variable is (@my example) m_MyPropPage.

that's the way you add pages to ctabctrl...
and know you like to switch from one tab to another you add with the wizard TCN_SELCHANGE message to your dialog class... and adds following code:

switch (m_tab.GetCurSel())
     {
         
case 0:    
//first page has index 0
// this is the first added page!
//be careful when adding your captions for the tabs
// because you need the same order when adding your pages
//otherwise you won't have the right caption to the right page ;)

//so remember your order in this switch-case block...
m_MyPropPage->ShowWindow( SW_SHOWNA );
m_MyPropPage2->ShowWindow( SW_HIDE ); // a second tab page
break;

case 1:    
m_MyPropPage->ShowWindow( SW_HIDE );
m_MyPropPage2->ShowWindow( SW_SHOWNA );
break;
}

that's all...