在控制启动/激活后,我如何获得ActiveX控件的HWND ?

时间:2022-11-22 07:33:00

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.

我正在使用Visual Studio 2008在c++中创建一个基于ATL 8.0的ActiveX控件。我需要创建一个子窗口并将其附加到ActiveX控件。

How do I get access to the HWND that is owned by the ActiveX control?

我如何访问由ActiveX控件拥有的HWND ?

Which ATL function can I override in order to use the HWND after the control's window has been created?

在创建了控件的窗口后,为了使用HWND,我可以重写哪个ATL函数?

3 个解决方案

#1


2  

After some trial and error and I found the answer I was after.

经过反复试验,我找到了我想要的答案。

In the constructor of your ATL ActiveX control you to add the following line of code:

在ATL ActiveX控件的构造函数中,您可以添加以下代码行:

m_bWindowOnly = true;

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.

这将导致创建控件的窗口(而不只是重用父窗口的HWND)。在此之后,控制类的m_hWnd成员可用于访问控制窗口的HWND。

#2


1  

ActiveX would allow you to define your own methods on your own interface (to address Brians assumption), but that likely won't help here. The ActiveX control might very well be created by another component. ATL too is irrelevant - it's a C++ template library that wraps COM interfaces.

ActiveX允许您在自己的接口上定义自己的方法(以解决Brians的假设),但是在这里可能不会有帮助。ActiveX控件很可能由另一个组件创建。ATL也是不相关的——它是一个封装COM接口的c++模板库。

The function you need here is IOleWindow::GetWindow. I'm not sure what you mean by "override an ATL function to use the HWMD". Once you have retrieved the HWND, you can pass it to any function that uses an HWND. For instance, as the parent in SetParent(child, parent)

您需要的函数是IOleWindow::GetWindow。我不知道你说的“覆盖一个ATL函数来使用HWMD”是什么意思。一旦您检索到HWND,您可以将它传递给任何使用HWND的函数。例如,作为SetParent中的父(子、父)

#3


-1  

[Full Disclosure]: I'm not that familiar with ActiveX or ATL, but I hope this is at least somewhat helpful.

我并不熟悉ActiveX或ATL,但我希望这至少能有所帮助。

If ActiveX allows you to define arbitrary methods on your object, try to expose a function that you can call that will simply return the value of the HWND to you (the control almost certainly knows its own HWND). That way you can call GetActiveXHwnd() to get the necessary handle, which you would then use for further manipulation.

如果ActiveX允许您在对象上定义任意的方法,那么尝试公开一个您可以调用的函数,它将简单地将HWND的值返回给您(该控件几乎肯定知道它自己的HWND)。这样,您就可以调用GetActiveXHwnd()来获取必要的句柄,然后您将使用它来进一步操作。

#1


2  

After some trial and error and I found the answer I was after.

经过反复试验,我找到了我想要的答案。

In the constructor of your ATL ActiveX control you to add the following line of code:

在ATL ActiveX控件的构造函数中,您可以添加以下代码行:

m_bWindowOnly = true;

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.

这将导致创建控件的窗口(而不只是重用父窗口的HWND)。在此之后,控制类的m_hWnd成员可用于访问控制窗口的HWND。

#2


1  

ActiveX would allow you to define your own methods on your own interface (to address Brians assumption), but that likely won't help here. The ActiveX control might very well be created by another component. ATL too is irrelevant - it's a C++ template library that wraps COM interfaces.

ActiveX允许您在自己的接口上定义自己的方法(以解决Brians的假设),但是在这里可能不会有帮助。ActiveX控件很可能由另一个组件创建。ATL也是不相关的——它是一个封装COM接口的c++模板库。

The function you need here is IOleWindow::GetWindow. I'm not sure what you mean by "override an ATL function to use the HWMD". Once you have retrieved the HWND, you can pass it to any function that uses an HWND. For instance, as the parent in SetParent(child, parent)

您需要的函数是IOleWindow::GetWindow。我不知道你说的“覆盖一个ATL函数来使用HWMD”是什么意思。一旦您检索到HWND,您可以将它传递给任何使用HWND的函数。例如,作为SetParent中的父(子、父)

#3


-1  

[Full Disclosure]: I'm not that familiar with ActiveX or ATL, but I hope this is at least somewhat helpful.

我并不熟悉ActiveX或ATL,但我希望这至少能有所帮助。

If ActiveX allows you to define arbitrary methods on your object, try to expose a function that you can call that will simply return the value of the HWND to you (the control almost certainly knows its own HWND). That way you can call GetActiveXHwnd() to get the necessary handle, which you would then use for further manipulation.

如果ActiveX允许您在对象上定义任意的方法,那么尝试公开一个您可以调用的函数,它将简单地将HWND的值返回给您(该控件几乎肯定知道它自己的HWND)。这样,您就可以调用GetActiveXHwnd()来获取必要的句柄,然后您将使用它来进一步操作。