Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Show MessageBox after CDialog is visible

Posted on 2003-03-05
Medium Priority
Last Modified: 2013-11-20
I want a CDialog dialog to launch the MessageBox based on data it gets in OnInitDialog(). But the MessageBox must only be displayed after the dialog is visble.

How do I do this?

Question by:doubletreemutt

Expert Comment

ID: 8076971
try a PostMessage from the InitDialog, before the return TRUE and write a handler for the message, show your message box in this.


ON_MESSAGE(WM_USER+101, OnUserMessage)

BOOL CMyDialog::OnInitDialog()
   CDialog::OnInitDialog() ;
   //acquire data?
   PostMessage(WM_USER+101, 0, 0) ;
   return TRUE ;

LRESULT CMyDialog::OnUserMessage(WPARAM wPar, LPARAM lPar)
  AfxMessageBox("Init done") ;
  return 0 ;

add this line to your header
afx_msg LRESULT OnUserMessage(WPARAM wPar, LPARAM lPar) ;

or, you could start a timer from OnInitDialog after you acquire data, then have the message shown from the timer routine, and kill the timer, you could use a boolean variable to indicate if OnInitDialog is completed

or u could map ON_SHOW_WINDOW()

there might be more ways..
LVL 23

Accepted Solution

Roshan Davis earned 400 total points
ID: 8077354
You can do this on after your first OnPaint Call

void CYourDlg::OnPaint()
     static bool bFirst = true;
     if ( bFirst )
          bFirst = false;
          // Show your message box here

Good Luck

Author Comment

ID: 8082027
Thanks roshmon that works perfectly.

Thanks also to Priyesh - I had tried your first and third solutions already - both displayed the MessageBox() before the dialog was visible. A timer would work but I was looking for something simpler like the OnPaint.


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question