Execute function after displaying a dialog box

I am using the MFC wizard with CPropertyPages. Is there a way to call a function after the page is shown? At the moment, the function starts when I click the "Next" button on the previous page.

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

Thank you for your help!

+4
source share
1 answer

It is usually sufficient to override OnSetActive (). However, this method is called before CPropertyPage becomes visible and focused. If you need to complete the task after showing the page, you must send your own message to 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() 
+2
source

Source: https://habr.com/ru/post/1443610/


All Articles