Solved

How to add dynamic propertypage

Posted on 2000-05-01
8
402 Views
Last Modified: 2013-11-20
How to dynamically add property page to propertysheet.( I am writting in dialog based application)
0
Comment
Question by:yesnathan22
  • 5
  • 2
8 Comments
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2768464
Call CPropertySheet::AddPage()
0
 

Expert Comment

by:degarn
ID: 2768488
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
 

Author Comment

by:yesnathan22
ID: 2768563
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
 

Expert Comment

by:degarn
ID: 2768761
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:yesnathan22
ID: 2768854

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
 

Expert Comment

by:degarn
ID: 2768996
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
 

Accepted Solution

by:
degarn earned 50 total points
ID: 2769051
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
 

Expert Comment

by:degarn
ID: 2769074
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now