<p>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. </p>

<p>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?</p>

[{'answer_id': 26679, 'author': 'Jared Updike', 'author_id': 2543, 'author_profile': 'https://Stackoverflow.com/users/2543', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>edit: Frank\'s advice is right on. <a href="https://msdn.microsoft.com/en-us/library/ms974564.aspx" rel="nofollow noreferrer">Here\'s the link on scripting events.</a></p>\n\n<p>My strategy was to call a C++ function called MyUpdate (which implements IConnectionPoint) when I wanted to force updates in the browser.</p>\n\n<p>(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.)</p>\n\n<p>On the browser side, the JavaScript code has the global variable referencing the object, followed by "::", followed by the method name:</p>\n\n<pre><code>function Uploader::MyUpdate()\n{\n    // ... code to fetch the current state of various\n    // properties from the Uploader object and do something with it\n    // for example check Uploader.IsActive and show or hide an HTML div\n}\n</code></pre>\n'}, {'answer_id': 26684, 'author': 'Frank Krueger', 'author_id': 338, 'author_profile': 'https://Stackoverflow.com/users/338', 'pm_score': 4, 'selected': True, 'text': '<p><em>Please</em> 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.</p>\n\n<p>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 <a href="http://msdn.microsoft.com/en-us/library/ms221608.aspx" rel="noreferrer"><code>IDispatch</code></a> interface.</p>\n\n<p>For events, you need to learn about <a href="http://msdn.microsoft.com/en-us/library/98b11x9k(VS.80).aspx" rel="noreferrer">Connection Points</a>.</p>\n'}]
['https://Stackoverflow.com/questions/26536', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1942/']