views:

1679

answers:

2

My coworker and I have encountered a nasty situation where we have to use an active X control to manipulate a web camera on a page. Is it possible to assign a javascript event handler to a button in the active x control so that it would fire an action on the page when clicked, or do we have to create a button on the html page itself that manipulates the Active X Control and then can fire any necessary actions on the page?

+1  A: 

Yes! You can throw events in C++/ActiveX land which makes the JavaScript code run an event handler function. I was even able to make an entire invisible ActiveX control (same color as page background) with no buttons or visual feedback that did all of its GUI work through JavaScript and CSS.

edit: Frank's advice is right on. Here's the link on scripting events.

My strategy was to call a C++ function called MyUpdate (which implements IConnectionPoint) when I wanted to force updates in the browser.

(Also, I made sure to pump Windows messages in the Fire_MyUpdate method because sometimes JavaScript code would call back into C++ land by calling methods on the ActiveX control; this avoids freezing up the browser and ensures that the JavaScript GUI stays responsive, e.g. for a Cancel button.)

On the browser side, the JavaScript code has the class (or was it the object), followed by "::", followed by the method name:

function Uploader::MyUpdate()
{
    // ... code to fetch the current state of various
    // properties from the Uploader object and do something with it
    // for example check Uploader.IsActive and show or hide an HTML div
}
Jared Updike
+4  A: 

Please just use an existing ActiveX control. Like Flash or Silverlight. Flash has built-in webcam support and is controllable via JavaScript. Silverlight doesn't have built-in camera support, but it's JavaScript integration is fantastic.

If you must write your own then fret not, it is trivial to get it to interact with JavaScript. You just have to expose the IDispatch interface.

For events, you need to learn about Connection Points.

Frank Krueger