Solved

Auto Closing A Diaglog Box/Message Box

Posted on 1998-05-07
11
502 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:fredmastro
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:galkin
Comment Utility
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
 
LVL 2

Author Comment

by:fredmastro
Comment Utility
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
 

Expert Comment

by:bobplace
Comment Utility
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
 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
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
 

Expert Comment

by:bobplace
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 10

Expert Comment

by:RONSLOW
Comment Utility
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
 
LVL 2

Author Comment

by:fredmastro
Comment Utility
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
 
LVL 3

Expert Comment

by:shaig
Comment Utility
I'm going to try that code you gave me RONSLOW.
0
 
LVL 2

Author Comment

by:fredmastro
Comment Utility
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
 
LVL 2

Author Comment

by:fredmastro
Comment Utility
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
 
LVL 10

Accepted Solution

by:
RONSLOW earned 70 total points
Comment Utility
My answer seems to have gone missing ... EE seems to be having a bit of trouble lately.

0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now