views:

352

answers:

2

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

+2  A: 

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

Naveen
+9  A: 

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.

Rob