Display a MessageBox in CDialog::OnActivate()
-
First of all I am new to C++ and in particular MFC, but I am making some minor changes to a project that I downloaded from here and the final change I need to make is to ask the user a question right after the dialog has loaded. In Visual FoxPro I would put this in the Activate of the Dialog, but in MFC this causes a multitude of issues such as: 1. The dialog doesn't actually display, so there is just a MessageBox in the middle of the screen. - The dialog displays after I click OK on the message which is understandable. 2. The Activate runs many times while the dialog is loading which causes any code I put in there to run many times (I put a flag in there to make it run only once.) My OnActivate is shown bellow:
afx_msg void CdotNetInstallerDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimised) { CDialog::OnActivate(nState, pWndOther, bMinimised); // Chris Ormerod 3/Dec/2003 if (m_bRunFromReboot) { // Make sure it doesn't run again. m_bRunFromReboot = false; if (MessageBox("Continue with installation?", "Requirements Checker", MB_YESNO | MB_ICONQUESTION) == IDYES) ResumeInstall(); } return; }
Can somebody please tell me where I should put this code? I have figured that putting it in OnActivate is probably wrong. Thanks, Chris Ormerod -
First of all I am new to C++ and in particular MFC, but I am making some minor changes to a project that I downloaded from here and the final change I need to make is to ask the user a question right after the dialog has loaded. In Visual FoxPro I would put this in the Activate of the Dialog, but in MFC this causes a multitude of issues such as: 1. The dialog doesn't actually display, so there is just a MessageBox in the middle of the screen. - The dialog displays after I click OK on the message which is understandable. 2. The Activate runs many times while the dialog is loading which causes any code I put in there to run many times (I put a flag in there to make it run only once.) My OnActivate is shown bellow:
afx_msg void CdotNetInstallerDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimised) { CDialog::OnActivate(nState, pWndOther, bMinimised); // Chris Ormerod 3/Dec/2003 if (m_bRunFromReboot) { // Make sure it doesn't run again. m_bRunFromReboot = false; if (MessageBox("Continue with installation?", "Requirements Checker", MB_YESNO | MB_ICONQUESTION) == IDYES) ResumeInstall(); } return; }
Can somebody please tell me where I should put this code? I have figured that putting it in OnActivate is probably wrong. Thanks, Chris OrmerodThanks to GeMe_Hendrix about 10 posts below this one I have the answer (I should look before I post): Try creating your own custom message ad handler for it first therefore at the top of your dialog CPP file... #define WM_MYOWNMESSAGE WM_USER + 1001; ... Then in the header file put... afx_msg LRESULT OnMyOwnMessage(WPARAM wParam, LPARAM lParam); ...Then the appropriate body for it... LRESULT CMyDialog::OnMyOwnMessage(WPARAM wParam, LPARAM lParam) { ... Show the file dialog box (I know it has to be modal) return 0; }; ... And finally in the body put... ON_MESSAGE(WM_MYOWNMESSAGE, OnMyOwnMessage) ... in the BEGIN_MESSAGE_MAP section... ... To call the message handler put this in the OnInitDialog function just before it returns... PostMessage(WM_MYOWNMESSAGE, 0, 0); And as a bonus I got an explanation of the message queue. Chris.