How to override CPropertySheet::RemovePage(int nPage)?
-
Int the following code, I'm overriding CPropertySheet::RemovePage(int nPage) How can I return a pointer to cdxCDynamicPropPage? class cdxCDynamicPropSheet:public CPropertySheet {} class cdxCDynamicPropPage :public CPropertyPage{} void cdxCDynamicPropSheet::RemovePage( int nPage ) { ASSERT_VALID(this); // remove the page externally if (m_hWnd != NULL) SendMessage(PSM_REMOVEPAGE, nPage); cdxCDynamicPropPage* page = ??? page->m_pSheet = NULL; }
-
Int the following code, I'm overriding CPropertySheet::RemovePage(int nPage) How can I return a pointer to cdxCDynamicPropPage? class cdxCDynamicPropSheet:public CPropertySheet {} class cdxCDynamicPropPage :public CPropertyPage{} void cdxCDynamicPropSheet::RemovePage( int nPage ) { ASSERT_VALID(this); // remove the page externally if (m_hWnd != NULL) SendMessage(PSM_REMOVEPAGE, nPage); cdxCDynamicPropPage* page = ??? page->m_pSheet = NULL; }
Use
CPropertySheet::GetPage
before sending the message to get a pointer to theCPropertyPage
. Then use DYNAMIC_DOWNCAST to cast a pointer to your derivedcdxDynamicPropPage
class.cdxCDynamicPropPage* pPage = DYNAMIC_DOWNCAST(cdxCDynamicPropPage, this->GetPage(nPage) );
SendMessage(PSM_REMOVEPAGE, nPage);
Something like that. Remember, though, that a better way would be to call
CPropertySheet::RemovePage
instead of sending a message. This way, the property page window will be deleted, but the page object would remain, leaving the pointer returned byGetPage
valid. Here is a different implementation of your RemovePage method, which removes a page from a property sheet, and then fiddles with the page object.void cdxCDynamicPropSheet::RemovePage(int nPage)
{
ASSERT_VALID(this);// Call base class method to remove a page this\->CPropertySheet::RemovePage(nPage); // The page object still exists, so acquire a pointer to it cdxCDynamicPropPage\* pRemovedPage = DYNAMIC\_DOWNCAST( cdxCDynamicPropPage, this\->GetPage(nPage) ); ASSERT( pRemovedPage != NULL ); // Fiddle with the object pRemovedPage->SomeMethod( someParams );
}
Hope this helps. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
-
Use
CPropertySheet::GetPage
before sending the message to get a pointer to theCPropertyPage
. Then use DYNAMIC_DOWNCAST to cast a pointer to your derivedcdxDynamicPropPage
class.cdxCDynamicPropPage* pPage = DYNAMIC_DOWNCAST(cdxCDynamicPropPage, this->GetPage(nPage) );
SendMessage(PSM_REMOVEPAGE, nPage);
Something like that. Remember, though, that a better way would be to call
CPropertySheet::RemovePage
instead of sending a message. This way, the property page window will be deleted, but the page object would remain, leaving the pointer returned byGetPage
valid. Here is a different implementation of your RemovePage method, which removes a page from a property sheet, and then fiddles with the page object.void cdxCDynamicPropSheet::RemovePage(int nPage)
{
ASSERT_VALID(this);// Call base class method to remove a page this\->CPropertySheet::RemovePage(nPage); // The page object still exists, so acquire a pointer to it cdxCDynamicPropPage\* pRemovedPage = DYNAMIC\_DOWNCAST( cdxCDynamicPropPage, this\->GetPage(nPage) ); ASSERT( pRemovedPage != NULL ); // Fiddle with the object pRemovedPage->SomeMethod( someParams );
}
Hope this helps. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
It helped Thanks a lot :)