简体   繁体   中英

How do I know if I will get an HWND when embedding an ActiveX control in HTML?

I have a simple ATL ActiveX Control, implemented in C++.

If I embed the control in a web page with something like:

   <object id="api"
            classid="CLSID:<guid here>"
            height=400
            width=800></object>

I know I can get an HWND from the control in m_hWnd if I set m_bWindowOnly = true; in my coclass constructor. This works ok.

If I were to try to instantiate this ActiveX control from Javascript, the process looks like:

var object = new ActiveXObject("registeredControlString");

But I don't get an HWND, and I am not sure how I might insert this into the DOM.

My Question:

In what situations will I get an HWND that I can reference from the control?

You won't get hwnd by constructing from new ActiveXObject since your CComControl::CreateControlWindow() is only called during in-place activation, and javascript simply does not have the type system to support the COM interfaces required for in-place activation.

If your control is going to be used as a UI-less COM server (like here in your script) design your ActiveX to work without a window handle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM