Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to override CPropertySheet::RemovePage(int nPage)?

How to override CPropertySheet::RemovePage(int nPage)?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mfc_surfer
    wrote on last edited by
    #1

    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; }

    A 1 Reply Last reply
    0
    • M mfc_surfer

      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; }

      A Offline
      A Offline
      Antti Keskinen
      wrote on last edited by
      #2

      Use CPropertySheet::GetPage before sending the message to get a pointer to the CPropertyPage. Then use DYNAMIC_DOWNCAST to cast a pointer to your derived cdxDynamicPropPage 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 by GetPage 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.

      M 1 Reply Last reply
      0
      • A Antti Keskinen

        Use CPropertySheet::GetPage before sending the message to get a pointer to the CPropertyPage. Then use DYNAMIC_DOWNCAST to cast a pointer to your derived cdxDynamicPropPage 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 by GetPage 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.

        M Offline
        M Offline
        mfc_surfer
        wrote on last edited by
        #3

        It helped Thanks a lot :)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups