?
Solved

Shutting down a DoModal dialog

Posted on 2003-03-31
3
Medium Priority
?
1,006 Views
Last Modified: 2013-11-20
How can I get a DoModal dialog to shut down by itself ?  I have a modal dialog that I open up for the user to provide his login and password.  Sometimes these are stored in a file, and in that case, I just want the dialog to fill it in by itself and close itself down.

However, if I use OnOK(), EndDialog() or DestroyWindow, I get a crash.

Any ideas?

0
Comment
Question by:Claus
[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
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 8238608
Call CDialog::OnOK() or CDialog::OnCancel(). If this doesn't work in OnInitDialog, set timer in OnInitDialog and close dialog in OnTimer function:

BOOL CMyDlg::OnInitDialog()
{
    // ...

    if ( ... )    // auto-close needed
        SetTimer(ID_TIMER, 20, NULL);

    return TRUE;
}

void CMyDlg::OnTimer(UINT nIDEvent)
{
    if ( nIDEvent == ID_TIMER )
    {
        KillTimer(ID_TIMER);            // we don't need it more

        CDialog::OnOK();
    }
     
    CDialog::OnTimer(nIDEvent);
}
0
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 8238624
It should be possible to call EndDialog() from with OnInitDialog()
without crash ... I used this often without problems.

ZOPPO
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 8239835


 If I was you I would either:

  1) Don't display the dialog at all and log the user in automatically. If name and pw are on file login silently.

  2) Leave the Dialog up, file in the name and password but allow the user to hit the 'Login' button.


  Flashing a dialog for an instance can be disconcerting.


 
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 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