CBegin dlg; if(dlg.DoModal()!=IDCANCEL) { OnOK(); } BOOL CBegin::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here SetTimer(1, 2000, NULL); //1:Specifies a nonzero timeridentifier //2000:Specifies the time-out value, in milliseconds. //NULL:Pointer to the function...if it's NULL, the system posts a WM_TIMER message to the application queue. return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CBegin::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default KillTimer(1); //1:the timer identifier CDialog::OnCancel(); CDialog::OnTimer(nIDEvent); }