suresh
suresh

Reputation:

Close or discard MFC dialog after a given period of time

how to close or discard a MFC dialog box Automatically after 10 seconds.

Upvotes: 3

Views: 4296

Answers (2)

Rob
Rob

Reputation: 78688

Declare an ID for your timer, i.e. in your CMyDialog.h somewhere:

static const UINT ID_MY_TIMER = 1000;

Create a timer in your OnInitDialog function:

SetTimer(ID_MY_TIMER, 10000, NULL); // 10000ms = 10 secs

Add a handler for WM_TIMER (the generated function will be called OnTimer):

void CMyDialog::OnTimer(UINT_PTR nIDEvent)
{
    if (nIDEvent == ID_MY_TIMER)
    {
        EndDialog(IDOK);
    }
    ...
}

Replace IDOK with IDCANCEL depending on what you return result you want from DoModal.

Upvotes: 11

Naveen
Naveen

Reputation: 73473

Use SetTimer with 10 seconds timeout. On the timer message handler post close message.

Upvotes: 2

Related Questions