[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

How to add dynamic propertypage

How to dynamically add property page to propertysheet.( I am writting in dialog based application)
0
yesnathan22
Asked:
yesnathan22
  • 5
  • 2
1 Solution
 
V_BapatCommented:
Call CPropertySheet::AddPage()
0
 
degarnCommented:
With classes CYourPorpPg, CYourPropSheet,

Declare a member variable of type CYourPropPg in your Propertysheet class :
CYourPropPg m_YourPg;

Then anyway you want, you can call the 'AddPage(CPorpertyPg* pPage)' member function of your propertysheet.

If you want the propertyPage to be loaded when your propertysheet is already shown modal, call AddPage from a message handler in your propertysheet (or a property page that is already loaded in it) :
AddPage(&m_YourPg);

Otherwhise, call it from anywhere the same way, befor you call the Domodal on your Propertysheet :

CYourPropsheet PSheet;
PSheet.AddPage(&PSheet.m_YourPg);
PSheet.DoModal();

Btw, in this case, calls to 'AddPage' are oftenly made in the propertysheet constructor.

Hope this helps...
Let me know if you need more help...
0
 
yesnathan22Author Commented:
Hello degarn

            My propertysheet contains five pages. after displaying third page i want to display the fourth page dynamically. i.e) i am writting Resume builder.In third page i want get input from the user - for how many number of projects he is going to put in his resume.Depends on the number i should display fourth page.Page four-1, Page four-2 .....like that. For that i declare a pointer of type CPropFour. allocate memory for that  and add to the propertysheet. It's work well.

i am calling the propertysheet DoModal in OnOk button of the dialog(Program is dialog based).
i am creating the dynamic pages in OnWizredNext of page 3.

this is the sample
BOOL CResBuilderDlg::OnInitDialog()
{
      p1.Construct(IDD_PROPPAGE_MEDIUM1,0);
p2.Construct(IDD_PROPPAGE_MEDIUM2,0);
p3.Construct(IDD_PROPPAGE_MEDIUM3,0);
p4.Construct(IDD_PROPPAGE_MEDIUM4,0);
p5.Construct(IDD_PROPPAGE_MEDIUM5,0);

ps.SetWizardMode();
ps.AddPage(&p1);
ps.AddPage(&p2);
ps.AddPage(&p3);
}

void CResBuilderDlg::OnOK()
{
 ps.DoModal();      
 //CDialog::OnOK();
}


In PropertyPage3

LRESULT CPropPage3::OnWizardNext()
{

CPropertySheet* psheet = (CPropertySheet*) GetParent();
CPropPage4 *pa4;
pa4=new CPropPage4;
psheet->AddPage(pa4);
}

Its work well.But if am adding the fifth to property sheet the fourth page doesn't display.

the code is


BOOL CResBuilderDlg::OnInitDialog()
{
      p1.Construct(IDD_PROPPAGE_MEDIUM1,0);
p2.Construct(IDD_PROPPAGE_MEDIUM2,0);
p3.Construct(IDD_PROPPAGE_MEDIUM3,0);
p4.Construct(IDD_PROPPAGE_MEDIUM4,0);
p5.Construct(IDD_PROPPAGE_MEDIUM5,0);

ps.SetWizardMode();
ps.AddPage(&p1);
ps.AddPage(&p2);
ps.AddPage(&p3);
ps.AddPage(&p5);// this is the only difference remaing things are same. Problem the fourth page doesn't display
}

Do understand my problem????



   
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
degarnCommented:
I feel like I understand yes !
In the OnWizardNext overridded fuction of your third page, you should call  ps.SetActivePage(pa4) after you have added that page.

Btw, if you 'll got to call SetActivePage(&ps.p5) in the OnWizardNext() function of the fourth page and also make calls to that function with correct pages as param in both OnWizardBack functions of those page.

A good issue to use standard wizard behaviour would be to add the two last pages in the OnWizardNExt of your third page :
LRESULT CPropPage3::OnWizardNext()
{
CPropertySheet* psheet = (CPropertySheet*) GetParent();
CPropPage4 *pa4;
pa4=new CPropPage4;
psheet->AddPage(pa4);
psheet->AddPage(&psheet->p5);
return CPropertyPage::OnWizardNext();
}

wtih the onInitDlg of your main Dlg like :
BOOL CResBuilderDlg::OnInitDialog()
{
p1.Construct(IDD_PROPPAGE_MEDIUM1,0);
p2.Construct(IDD_PROPPAGE_MEDIUM2,0);
p3.Construct(IDD_PROPPAGE_MEDIUM3,0);
p4.Construct(IDD_PROPPAGE_MEDIUM4,0);
p5.Construct(IDD_PROPPAGE_MEDIUM5,0);

ps.SetWizardMode();
ps.AddPage(&p1);
ps.AddPage(&p2);
ps.AddPage(&p3);
}
 
Hope this helps ...
0
 
yesnathan22Author Commented:

i did the same thing but there is one more problem.if i am getting the number from the user,
it  will display pages dynamically but if he move back and forth the program eat lot of memory and gives Assertion for out of memory.Is there any way to eleminate it???
0
 
degarnCommented:
This may occur because you don't destroy pages you don't need anymore.
If the user gets back to the beginning of the wizard you should override the OnWizardBack() function of the fourth page in order to destroy previously created pages.

Btw you could also do this in the OnSetActive function of your third page.
Handle a list of pointers to your dinamically constructed property pages as a member of your propertysheet so that you can find back those pages easily. Then  implement a loop on that list with those lines in it :

psheet->RemovePage(CurPgPtr);
delete CurPgPtr;

Perhaps, you could call CurPgPtr->Destroywindow(); but I don't feel like it's usefull. You should test...

Try and if you want more info on one of those points, only let me know...
0
 
degarnCommented:
Well, another thing, I read again your prvious comments and I wonder if the list of pointers is really usefull.
If the dinamically constructed page only appears once, you should have a member variable in which you would store that pointer and then, before create create the new property page, you should test if the pointer is filled :

if(psheet->m_p4)
{
psheet->RemovePage(psheet->m_p4);
psheet->RemovePage(&psheet->p5);
delete psheet->m_p4;
psheet->m_p4=NULL;
}

You could do this before creating the fourth page in the OnWizardNext function of your third page,
or in the OnSetActive() function of your third page.

Hope this helps...
0
 
degarnCommented:
If the fourth page can be instanciated many times at the same moment, the list will be a good issue.
In this case, don't forget to remove also the fifth page each time you turn back to the third one, cause otherwise, it is added each time to the property sheet and so, it could eat memory...

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now