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. Display a MessageBox in CDialog::OnActivate()

Display a MessageBox in CDialog::OnActivate()

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionbusiness
2 Posts 1 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.
  • C Offline
    C Offline
    Chris Ormerod
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • C 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 Ormerod

      C Offline
      C Offline
      Chris Ormerod
      wrote on last edited by
      #2

      Thanks 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.

      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