Close or cancel the MFC dialog after a certain period of time

how to close or cancel the MFC dialog automatically after 10 seconds.

+3
source share
2 answers

Declare an identifier for your timer, i.e. in CMyDialog.hsomewhere:

static const UINT ID_MY_TIMER = 1000;

Create a timer in your function OnInitDialog:

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 IDOKwith IDCANCELdepending on what you return from DoModal.

+12
source

Use SetTimer with a timeout of 10 seconds. The message closes the message handler timer message.

+2

Source: https://habr.com/ru/post/1710237/


All Articles