How to use OnTimer in modeless Dialog?
-
// dialog BOOL dlgWait::OnInitDialog(void) { CDialog::OnInitDialog(); SetTimer(1,500, NULL); return TRUE; } void dlgWait::OnTimer(UINT_PTR nIDEvent) { AfxMessageBox("aaaa"); CDialog::OnTimer(nIDEvent); }
dlgWait waitDlg; waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); // AfxMessageBox("aaaa"); would't display Sleep(10000); /* If change waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); to waitDlg.DoModal(); AfxMessageBox("aaaa"); would display */
-
// dialog BOOL dlgWait::OnInitDialog(void) { CDialog::OnInitDialog(); SetTimer(1,500, NULL); return TRUE; } void dlgWait::OnTimer(UINT_PTR nIDEvent) { AfxMessageBox("aaaa"); CDialog::OnTimer(nIDEvent); }
dlgWait waitDlg; waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); // AfxMessageBox("aaaa"); would't display Sleep(10000); /* If change waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); to waitDlg.DoModal(); AfxMessageBox("aaaa"); would display */
The problem is because of the Sleep(10000). By doing that, you prevent window messages to be processed, thus your timer message will only be processed after the sleep.
Cédric Moonen Software developer
Charting control [v1.4] -
// dialog BOOL dlgWait::OnInitDialog(void) { CDialog::OnInitDialog(); SetTimer(1,500, NULL); return TRUE; } void dlgWait::OnTimer(UINT_PTR nIDEvent) { AfxMessageBox("aaaa"); CDialog::OnTimer(nIDEvent); }
dlgWait waitDlg; waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); // AfxMessageBox("aaaa"); would't display Sleep(10000); /* If change waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); to waitDlg.DoModal(); AfxMessageBox("aaaa"); would display */
hanlei0000000009 wrote:
waitDlg.ShowWindow(SW_SHOW); // AfxMessageBox("aaaa"); would't display Sleep(10000);
Sleep (10000); will block message pumping.
-
// dialog BOOL dlgWait::OnInitDialog(void) { CDialog::OnInitDialog(); SetTimer(1,500, NULL); return TRUE; } void dlgWait::OnTimer(UINT_PTR nIDEvent) { AfxMessageBox("aaaa"); CDialog::OnTimer(nIDEvent); }
dlgWait waitDlg; waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); // AfxMessageBox("aaaa"); would't display Sleep(10000); /* If change waitDlg.Create(IDD_DLG_WAIT,NULL); waitDlg.ShowWindow(SW_SHOW); to waitDlg.DoModal(); AfxMessageBox("aaaa"); would display */
hanlei0000000009 wrote:
Sleep(10000);
anyways why you require sleep(10000) here!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/codeProject$$>