Link to home
Start Free TrialLog in
Avatar of doubletreemutt
doubletreemutt

asked on

Show MessageBox after CDialog is visible

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?

thanks
Doubletreemutt
Avatar of Priyesh
Priyesh

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

like

ON_MESSAGE(WM_USER+101, OnUserMessage)
DECLARE_MESSAGE_MAP()

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..
ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doubletreemutt

ASKER

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.

Doubletreemutt