[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Auto Closing A Diaglog Box/Message Box

Posted on 1998-05-07
11
Medium Priority
?
551 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1308304
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
ID: 1308305
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
ID: 1308306
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308307
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
ID: 1308308
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
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308309
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
ID: 1308310
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
ID: 1308311
I'm going to try that code you gave me RONSLOW.
0
 
LVL 2

Author Comment

by:fredmastro
ID: 1308312
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
ID: 1308313
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 210 total points
ID: 1308314
My answer seems to have gone missing ... EE seems to be having a bit of trouble lately.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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