Auto Closing A Diaglog Box/Message Box

How do I auto close a diaglog box and a message box. Are there two differnt commands if one's a message box? I'm trying to display a bitmap in a dialog box, or message box, and I don't know how to auto close it. I'm a beginner. Thanks for the help.
LVL 2
fredmastroAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

galkinCommented:
To close dialog box you need to send to it either IDCANCEL or IDOK WM_COMMAND messages SendMessage(WM_COMMAND, IDCANCEL)
To close message box the idea is the same but depends on message box style. If its style is MB_OK send IDOK if MB_YES send IDYES.
0
fredmastroAuthor Commented:
Start a timer, then when the timer has reached the limit, use PostMessage, and send a WM_CLOSE.  This will close the dialog.  We do something similar with a thread based progress bar.


0
bobplaceCommented:
The problem with a message box is that it sits and waits until the user dismisses it.  Your timer won't respond until the message box is dismissed anyway.  You really need a separate thread.

Dialog boxes are easy.. They can be written so the they will kill themselves after a certain time.

eg.
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
//{{AFX_MSG_MAP(CMyDialog)
...
ON_WM_TIMER()
...
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CMyDialog::OnInitDialog() {
  BOOL ok = CDialog::OnInitDialog();
  SetTimer((UINT)this, 10*1000, NULL);      // ten seconds
  return ok;
}

void CMyDialog::OnTimer(UINT nIDEvent) {
  if (nIDEvent == (UINT)this)      {
    CWnd* pParentFrame = GetParentFrame();
    DestroyWindow();
    if (pParentFrame) pParentFrame->SetActiveWindow();
  }
}

Perhaps you should use dialogs instead of message boxes so you can have more control over how they work.

0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

RONSLOWCommented:
If using post message is not what you need, then exactly what are you trying to do?  Both answers you received will solve the problem you listed, The first, if there are buttons there then second if there are not buttons.  

Can you explaine your problem a little better?
0
bobplaceCommented:
EE has stuffed up the questions and answers again !!!!!  Aaarrgghh!!

My answer has disappeared.  I had posted some source code for you and now bobplace's comments appear as my answer.

I hope Linda and the EE team can retrieve it so that I don't need to do all that work again.  If it doesn't magically re-appear, I'll post have to do some more work and post my answer as a comment again.
0
RONSLOWCommented:
I'll try to be more specific. I added a WM_CLOSE as suggested to me CSplshDlg class which is the dialog I want to close after 5 seconds.
Here is my WM_CLOSE section in my CSplshDlg class.

void CSplshDlg::OnClose()
{
      // TODO: Add your message handler code here and/or
        // call default
      
      CDialog::OnClose();
}

Now I have the CSplshDlg come up first, but I want it to close after 5 seconds and then load CMCADlg.  What would I put in this code segment above to do that? Do I have to add CMCADlg to CApp class or can I load it from here.
0
fredmastroAuthor Commented:
It would be best if you add the splash to the CMCADlg ( on it's OnInitDialog() ) and not as suggested, for the following reasons:
1. add to the OnClose of the splash dialog - a bizzare solution, is might work, but do you want your splash to open the programs main dialog or the oposite? if it is importent to show the CMCADlg only after the splash ends then hide it till then or use the splash's DoModal on the CMCADlg OnInitDialog() since he is not visible there yet.
2. Add to the app - The application should have the m_pMainWnd set to a valid value if you want things to work properly, so:
it is recommended if you know exactly what to do, if you don't, then don't mess with it.  You can add to your project a splash window component through the add-to-project/components-and-controls menu, that does all the work! although the code inserted by the component is a usual Microsoft low quality one, it works.
0
shaigCommented:
I'm going to try that code you gave me RONSLOW.
0
fredmastroAuthor Commented:
RONSLOW I would like to grade your answer. If you can supply a second answer since the first one somehow got rejected. I couldn't see it bofore, but I can now.  When you respond could you mention how I get the timer to open another dialog when it destroys the first dialog. I put your code in but I keep getting "unkown character '0xa0'".  Do I have to #include something? I've increased the points for you to 75.
0
fredmastroAuthor Commented:
The code I gave needs to be merged into yor dialog.  And appropriate changes made to your .h file.

This code came from my splash dialog class.  If I had known that is what you wanted, I could have posted the whole thing ... Or suggested you thy the splash screen component in VC (once you fix up the bugs documented in the KB )

Let me know if you would like my splash dialog class

0
RONSLOWCommented:
My answer seems to have gone missing ... EE seems to be having a bit of trouble lately.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.