没有窗口的CWnd继承类应该怎么使用OnTimer函数?
没有窗口的CWnd继承类应该如何使用OnTimer函数???
本身是一个C++类,后因为需求改为继承Cwnd
class AAA : public CObject
class AAA : public CWnd
现在要在AAA类中使用OnTimer,因为没有窗口所以没办法用。程序直接崩溃在下面的代码中。
请问如何在没有窗口的CWnd继承类中使用OnTimer啊???听说可以用SetTimer的最后一个参数的那个回调函数,请问具体该怎么用啊?
------解决方案--------------------
AAA类调用Create创建一个隐藏的窗体即可
------解决方案--------------------
你看看SetTimer这个API, 窗口句柄可以为空的, 然后你指定回调函数 就可以了
------解决方案--------------------
自己写回调函数可以了吧..
------解决方案--------------------
VOID CALLBACK TimerProc ( HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
处理WM_TIMER消息
}
SetTimer (hwnd, iTimerID, iMsecInterval, TimerProc) ;
本身是一个C++类,后因为需求改为继承Cwnd
class AAA : public CObject
class AAA : public CWnd
现在要在AAA类中使用OnTimer,因为没有窗口所以没办法用。程序直接崩溃在下面的代码中。
- C/C++ code
_AFXWIN_INLINE UINT_PTR CWnd::SetTimer(UINT_PTR nIDEvent, UINT nElapse, void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD)) { ASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse, lpfnTimer); }
请问如何在没有窗口的CWnd继承类中使用OnTimer啊???听说可以用SetTimer的最后一个参数的那个回调函数,请问具体该怎么用啊?
------解决方案--------------------
AAA类调用Create创建一个隐藏的窗体即可
------解决方案--------------------
你看看SetTimer这个API, 窗口句柄可以为空的, 然后你指定回调函数 就可以了
------解决方案--------------------
自己写回调函数可以了吧..
------解决方案--------------------
VOID CALLBACK TimerProc ( HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
处理WM_TIMER消息
}
SetTimer (hwnd, iTimerID, iMsecInterval, TimerProc) ;