SetTimer函数第3个参数怎么使用???(TimerProc),自己写了一个方法,但不知将其作为一个参数放进这个SetTimer中,有没有一个简单例子???
解决方案 »
- CImage在MFC上重新将处理后的图片绘制到view上
- 关闭注册表 报错“error C3861: 'RegcloseKey': identifier not found”
- 求助一个关于用VS2010修改现有VC++项目界面的问题
- 怎么样去掉cscrollview窗口的滚动条
- vc调用com组件
- 线程退出出错
- 请问:如何判断控件是否存在焦点?
- 我是菜鸟,问一下在VC工程里面如何定义一个CString类型的全局变量?
- 用CreateProcess创建一个进程,同时传参数的问题。
- 紧急求救
- 求助!异常捕获问题
- 用ShellExecute启动了一个Shell程序 Sample.exe ,怎样等到这个Sample.exe执行结束的时候,才执行下一条语句?
The SetTimer function creates a timer with the specified time-out value.
Syntax
UINT_PTR SetTimer( HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
ParametershWnd
[in] Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEvent parameter is ignored.
nIDEvent
[in] Specifies a nonzero timer identifier. If the hWnd parameter is NULL, this parameter is ignored. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored.
uElapse
[in] Specifies the time-out value, in milliseconds.
Windows NT/2000/XP: If uElapse is greater than 0x7fffffff, the timeout is set to 1.Windows 2000/XP: If uElapse is less than 10, the timeout is set to 10.Windows Server 2003: If uElapse is greater than 0x7fffffff, the timeout is set to 0x7fffffff. lpTimerFunc
[in] Pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc. If lpTimerFunc is NULL, the system posts a WM_TIMER message to the application queue. The hwnd member of the message's MSG structure contains the value of the hWnd parameter.
Return ValueIf the function succeeds and the hWnd parameter is NULL, the return value is an integer identifying the new timer. An application can pass this value to the KillTimer function to destroy the timer. If the function succeeds and the hWnd parameter is not NULL, then the return value is a nonzero integer. An application can pass the value of the nIDEvent parameter to the KillTimer function to destroy the timer.If the function fails to create a timer, the return value is zero. To get extended error information, call GetLastError.
{
//your code
}
我是用对话框上一个Static控件的SetTimer刚才试了一下 alon21 的方法,可以运行,但我在OnTimerProc这个方法里怎么控制这个Static的显示呢????
OnTimerProc 并不属于对话框这个类中的一个方法,怎么可以用GetDlgItem(ID_STATIC)呢?????
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
Parameters第一個是,窗口句柄hWnd,不用說了;
第二個是,Timer的ID,你在設置多個Timer的時候,就可以在TimerProc中加以區別了,是哪個Timer引發的.
第三個是,執行周期,以微秒為單位,如果是1秒就設置為1000.
第三個是,TimerPorc函數指針.
有什么办法操作 所说的 ID_STATIC 啊?????
to suisuibianbian:窗口的指针怎么传进来这个回调方法里呢,第1个参数是HWND怎么转换?????
CMyDlg * pDlg = (CMyDlg *)CWnd::FromHandle(hWnd);
GetDlgItem(hWnd,ID_STATIC)->SetWindowText('aaaa');
SetTimer(1,2000,(TIMERPROC)OnTimerProc); VOID CALLBACK OnTimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
{
//your code
}在 (TIMERPROC)OnTimerProc 中,怎么传????在调用之前,怎么声明?????
另外,这样设置Timer:
::SetTimer(GetSafeHwnd(),1,2000,(TIMERPROC)OnTimerProc);
如果是外部調用.就可::SetTimer(AfxGetApp()->m_pMainWnd->m_hWnd,ID_TIMER1,nSecond *1000 ,(TIMERPROC)OnTimerProc);