c++mfccpropertysheet

Run function after dialog is shown


I am using a MFC wizard with CPropertyPages. Is there any way of calling a function after the page is shown? At the moment the function starts when I hit the "Next"-button of the previous page.

I tried to call the function from OnShowWindow, OnCreate, OnSetActive, DoModal, but none of them worked.

Thanks for your help!


Solution

  • Usually it's enough to override OnSetActive(). However, this method is called before the CPropertyPage is made visible and focused. If you have to perform a task after the page is shown, you have to post your own message in OnSetActive:

    // This message will be received after CMyPropertyPage is shown
    #define WM_SHOWPAGE WM_APP+2
    
    BOOL CMyPropertyPage::OnSetActive() {
        if(CPropertyPage::OnSetActive()) {
            PostMessage(WM_SHOWPAGE, 0, 0L); // post the message
            return TRUE;
        }
        return FALSE;
    }
    
    LRESULT CMyPropertyPage::OnShowPage(UINT wParam, LONG lParam) {
        MessageBox(TEXT("Page is visible. [TODO: your code]"));
        return 0L;
    }
    
    BEGIN_MESSAGE_MAP(CMyPropertyPage,CPropertyPage)
        ON_MESSAGE(WM_SHOWPAGE, OnShowPage) // add message handler
        // ...
    END_MESSAGE_MAP()