How do I get the HWND for an ActiveX control after initializing / activating the control?

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 an ActiveX control.

How do I access an HWND owned by an ActiveX control?

Which ATL function can be overridden to use the HWND after the control window is created?

+1


source to share


3 answers


After some trial and error, and I found the answer I got after.

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



m_bWindowOnly = true;

      

This causes the window to be created for the control (rather than just reusing the HWND of the parent window). The m_hWnd member of the control class can then be used to access the HWND for the control window.

+2


source


ActiveX will let you define your own methods on your own interface (to make Brians decide), but that probably won't help. An ActiveX control could well be created by another component. ATL doesn't matter either - it's a C ++ templating library that wraps COM interfaces.



Here you need the IOleWindow :: GetWindow function. I'm not sure what you mean by "overriding ATL function to use HWMD". Once you've got the HWND, you can pass it to any function that uses the HWND. For example as parent in SetParent (child, parent)

+1


source


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

If ActiveX allows you to define arbitrary methods on your object, try exposing a function that you can call that will simply return the HWND value to you (the control almost certainly knows its own HWND). This way you can call GetActiveXHwnd()

to get the handle you want, which you would then use for further manipulation.

-1


source







All Articles