在初始化/激活控件后,如何获取 ActiveX 控件的 HWND? [英] How do I get the HWND for an ActiveX control after the control has been initialised/activated?
问题描述
我正在使用 Visual Studio 2008 在 C++ 中创建基于 ATL 8.0 的 ActiveX 控件.我需要创建一个子窗口并将其附加到 ActiveX 控件.
I am creating an ATL 8.0 based ActiveX control in C++ using Visual Studio 2008. I need to create a sub-window and attach it to the ActiveX control.
如何访问 ActiveX 控件拥有的 HWND?
How do I get access to the HWND that is owned by the ActiveX control?
为了在控件窗口创建后使用 HWND,我可以覆盖哪个 ATL 函数?
Which ATL function can I override in order to use the HWND after the control's window has been created?
推荐答案
经过反复试验,我找到了我想要的答案.
After some trial and error and I found the answer I was after.
在您的 ATL ActiveX 控件的构造函数中添加以下代码行:
In the constructor of your ATL ActiveX control you to add the following line of code:
m_bWindowOnly = true;
这会导致创建控件的窗口(而不仅仅是重用父窗口的 HWND).此后,控件类的 m_hWnd 成员可用于访问控件窗口的 HWND.
This causes the window for the control to be created (rather than just reusing the HWND of the parent window). After this the m_hWnd member of the control class can be used to access the HWND for the control's window.
这篇关于在初始化/激活控件后,如何获取 ActiveX 控件的 HWND?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!