I have 2 CPropertyPage objects; right now, the second page will only hit OnInitDialog if I click on the second page.
How can I initialize it right away when program starts?
I have 2 CPropertyPage objects; right now, the second page will only hit OnInitDialog if I click on the second page.
How can I initialize it right away when program starts?
You can add PSP_PREMATURE to the dwFlags field of each property page's m_psp data member (a PROPSHEETPAGE structure). This forces the actual creation of that page (thus calling its OnInitDialog() function) when the parent property sheet is created, rather than waiting until the page is selected.
The only online documentation I can find for this is now 'deprecated', but the technique does still work.
- dwFlags
...
PSP_PREMATUREThe page is created when the property sheet is created. Usually, the page is not created until the first time it is selected.
You can add this flag in the constructor for each page; something like this:
class MyPropPage : public CPropertyPage
{
public:
MyPropPage(UINT idd) : CPropertyPage(idd) {
m_psp.dwFlags |= PSP_PREMATURE; // Add the 'premature' flag on construction
//...
}
//...
};
You might want to use a WM_TIMER message in your CPropertySheet like this:
BOOL CMyPropertySheet::OnInitDialog()
{
SetTimer(1, 1, NULL);
return CPropertySheet::OnInitDialog();
}
void CMyPropertySheet::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 1)
{
KillTimer(1);
SetActivePage(1); // initialize second tab
SetTimer(2, 1, NULL);
}
else if (nIDEvent == 2)
{
KillTimer(2);
SetActivePage(0); // back to first tab
// to hide the initialization process, you might want to create
// CMyPropertySheet with the WS_VISIBLE style disabled and wait
// until all pages are initialized:
ShowWindow(SW_SHOW);
}
CPropertySheet::OnTimer(nIDEvent);
}