Skip to content

Instantly share code, notes, and snippets.

@botaor
Created March 5, 2013 15:08
Show Gist options
  • Save botaor/5090941 to your computer and use it in GitHub Desktop.
Save botaor/5090941 to your computer and use it in GitHub Desktop.
How to execute code after the dialog is just shown to the user in Windows MFC.
// Definition of the message code
#define WM_DIALOG_SHOW (WM_APP + 10)
// Functions that are members of the dialog class
class CMyDlg : public CDialog
{
...
afx_msg void OnWindowPosChanged( WINDOWPOS* lpwndpos );
afx_msg void OnDialogShow(WPARAM wp, LPARAM lp);
...
} ;
// Declaration of message map so that the functions are called
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
...
ON_WM_WINDOWPOSCHANGED()
ON_MESSAGE(WM_DIALOG_SHOW, OnDialogShow )
...
END_MESSAGE_MAP()
// Functions called when the messages are received by the dialog
// If you only want to execute the code once, you might have to use some sort of flag
void CMyDlg::OnWindowPosChanged( WINDOWPOS* lpwndpos )
{
CWnd::OnWindowPosChanged( lpwndpos );
if( lpwndpos->flags & SWP_SHOWWINDOW )
{
PostMessage( WM_DIALOG_SHOW, 0, 0);
}
}
void CMyDlg::OnDialogShow(WPARAM wp, LPARAM lp)
{
MessageBox( "Here we are", "Title" ) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment