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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Display a MessageBox right after a dialog is drawn on the screen?

Display a MessageBox right after a dialog is drawn on the screen?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 3 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.
  • U Offline
    U Offline
    usfesco
    wrote on last edited by
    #1

    hi all, I would like my dialog-based app to pop up a message box right after the dialog itself is shown on the screen... anyone knows how to do that? If I put a message box in my dialog's OnInitDialog like this: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); ...... AfxMessageBox("hello"); return TRUE; // return TRUE unless you set the focus to a control } the message box pops up before the main dialog appears, but I want the message box to pop up AFTER the main dialog appears. I've tried handling WM_SHOWWINDOW message, i.e., put the AfxMessageBox in the dialog's OnShowWindow() function, but it was the same thing as putting the AfxMessageBox in OnInitDialog() -- the message box still pops up before the main dialog appears. Thanks for your help in advance :-O

    PJ ArendsP A 2 Replies Last reply
    0
    • U usfesco

      hi all, I would like my dialog-based app to pop up a message box right after the dialog itself is shown on the screen... anyone knows how to do that? If I put a message box in my dialog's OnInitDialog like this: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); ...... AfxMessageBox("hello"); return TRUE; // return TRUE unless you set the focus to a control } the message box pops up before the main dialog appears, but I want the message box to pop up AFTER the main dialog appears. I've tried handling WM_SHOWWINDOW message, i.e., put the AfxMessageBox in the dialog's OnShowWindow() function, but it was the same thing as putting the AfxMessageBox in OnInitDialog() -- the message box still pops up before the main dialog appears. Thanks for your help in advance :-O

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      The easist way is post a custom message to your dialog from the OnInitDialog function, that way OnInitDialog will close, and the dialog will be created before the message is handled. In the custom message handler you call AfxMessageBox.

      #define WMU_POPUPMESSAGEBOX WM_APP;
      ...
      BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
      ...
      ON_MESSAGE(WMU_POPUPMESSAGEBOX, OnPopupMessageBox)
      END_MESSAGE_MAP()
      ...
      BOOL CTestDlg::OnInitDialog()
      {
      ...
      PostMessage(WMU_POPUPMESSAGEBOX, 0, 0);
      return TRUE;
      }

      HRESULT OnPopupMessageBox(WPARAM, LPARAM)
      {
      AfxMessageBox(_T("Hello"));
      return 0;
      }


      [

      ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

      Within you lies the power for good; Use it!

      U 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        The easist way is post a custom message to your dialog from the OnInitDialog function, that way OnInitDialog will close, and the dialog will be created before the message is handled. In the custom message handler you call AfxMessageBox.

        #define WMU_POPUPMESSAGEBOX WM_APP;
        ...
        BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
        ...
        ON_MESSAGE(WMU_POPUPMESSAGEBOX, OnPopupMessageBox)
        END_MESSAGE_MAP()
        ...
        BOOL CTestDlg::OnInitDialog()
        {
        ...
        PostMessage(WMU_POPUPMESSAGEBOX, 0, 0);
        return TRUE;
        }

        HRESULT OnPopupMessageBox(WPARAM, LPARAM)
        {
        AfxMessageBox(_T("Hello"));
        return 0;
        }


        [

        ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

        U Offline
        U Offline
        usfesco
        wrote on last edited by
        #3

        Thanks dear Mr. Arends, It Worked! :rose: :laugh:

        1 Reply Last reply
        0
        • U usfesco

          hi all, I would like my dialog-based app to pop up a message box right after the dialog itself is shown on the screen... anyone knows how to do that? If I put a message box in my dialog's OnInitDialog like this: BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); ...... AfxMessageBox("hello"); return TRUE; // return TRUE unless you set the focus to a control } the message box pops up before the main dialog appears, but I want the message box to pop up AFTER the main dialog appears. I've tried handling WM_SHOWWINDOW message, i.e., put the AfxMessageBox in the dialog's OnShowWindow() function, but it was the same thing as putting the AfxMessageBox in OnInitDialog() -- the message box still pops up before the main dialog appears. Thanks for your help in advance :-O

          A Offline
          A Offline
          avenger_sb25
          wrote on last edited by
          #4

          Hey, i used the following technique in my program to solve a same problem. when you recieve WM_INITDIALOG message, call ShowWindow(hDlg,SW_SHOW); //plese write the MFC equivalent urself;P) After that, you can call MessageBox to do your stuff... That's simpler solution.


          Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs

          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