CWnd::SetTimer UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) ); ParametersnIDEventSpecifies a nonzero timer identifier.nElapseSpecifies the time-out value, in milliseconds.lpfnTimerSpecifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application’s message queue and handled by the CWnd object.
BOOL KillTimer( int nIDEvent ); Specifies the outcome of the function. The value is nonzero if the event was killed. It is 0 if the KillTimer member function could not find the specified timer event.ParametersnIDEventThe value of the timer event passed to SetTimer.
看一下这段很简单的程序: 为什么void CMy3Dlg::OnTimer(UINT nIDEvent)一点用都没有?单步执行时根本没进入函数体。void CMy3Dlg::OnRolchange() //命令按钮的处理函数,调用SetTimer { // TODO: Add your control notification handler code here CWnd::SetTimer(1, 1000, NULL); }void CMy3Dlg::OnTimer(UINT nIDEvent) { CMy3Dlg dlg;
if(nIDEvent == 1) { dlg.m_strDisplay="I am succes!"; dlg.DoModal(); } CDialog::OnTimer(nIDEvent);}
在OnTimer事件中写处理程序
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
ParametersnIDEventSpecifies a nonzero timer identifier.nElapseSpecifies the time-out value, in milliseconds.lpfnTimerSpecifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application’s message queue and handled by the CWnd object.
Specifies the outcome of the function. The value is nonzero if the event was killed. It is 0 if the KillTimer member function could not find the specified timer event.ParametersnIDEventThe value of the timer event passed to SetTimer.
为什么void CMy3Dlg::OnTimer(UINT nIDEvent)一点用都没有?单步执行时根本没进入函数体。void CMy3Dlg::OnRolchange() //命令按钮的处理函数,调用SetTimer
{
// TODO: Add your control notification handler code here
CWnd::SetTimer(1, 1000, NULL);
}void CMy3Dlg::OnTimer(UINT nIDEvent)
{
CMy3Dlg dlg;
if(nIDEvent == 1)
{
dlg.m_strDisplay="I am succes!";
dlg.DoModal();
}
CDialog::OnTimer(nIDEvent);}