描述:
用ATL写ActiveX控件,控件类派生于CWindowImpl包装了一个CWindow
但由于CWindow句柄无效,无法用CWindow成员函数SetTimer设置定时器?如何解决.
ATL控件的CreateWindow是不是由客户程序完成的啊.
急!
解决方案1:
如果窗口创建后m_hWnd为NULL,估计是你创建的方法不对吧?
解决方案2: 这是因为你的ActiveX控件是windowless(容器为IE,richedit一般都是这样),所以m_hWnd=000000
自己创建一个接口,由外部传入HWND, 在控件类里做为一个属性保存
UINT_PTR SetTimer(
HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
其中nIDEvent应该是控件类的this指针
lpTimerFunc是控件类的静态成员函数
这样你就可以访问控件类的数据成员了
注意
UINT_PTR SetTimer(
HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);如果hWnd=NULL,nIDEvent是无效的,这也是为什么需要外部传入HWND的原因
CWindow句柄无效?
如果HWND不能用,就用回调。
UINT_PTR SetTimer( HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);
最后一个参数,注意到没?
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.
VOID CALLBACK TimerProc( HWND hwnd,
UINT uMsg,
UINT_PTR idEvent,
DWORD dwTime
);
http://dev.csdn.net/develop/article/26/26243.shtm
解决方案5: CMyWindow wnd;
wnd.Create( NULL, CWindow::rcDefault, _T("Hello"),WS_OVERLAPPEDWINDOW|WS_VISIBLE );
wnd.SetTimer......
......
您可能想查找下面的文章:
- 为什么我的VC6,在创建ATL对象中我选择了最后一项,Ra我看到网上别人有一个CWindowImpldeskband
- 初学ATL,在基于CWindowImpl的窗口上,怎样才能加上按钮、输入框等?哪里有这方面的代码实例?
- 如何在继承自CWindowImpl的窗口中动态创建多个static控件,并设置其属性
- 怎么样才能在CWindowImpl为基类的toolbar里放上网页
- WTL,CCodePageCombo继承CComboBoxT<ATL::CWindow>类,需要响应下拉菜单CloseUp的消息
- 如何使CWindow窗体具有浏览器功能?
- [60分]ATL,非CWindow派生的类,如何得到m_hWnd?用_Module不行啊
- 如何用CWindowImpl创建一个没有标题栏和边框的窗口?
- CWindowImpl如何销毁?
- ATL中,CTest继承CWindowImpl,并且已经创建了窗口。当发送自定义消息,如WM_USER+1,窗口没收到。怎样发送自定义消息?