问题
I am developing a windows application in C#.NET. In one of my winform I have added a WebBrowser control. In this webbrowser control I have opened an asp page from my local website. Now in this webpage there is one flash object which is used to play swf files. Now my question is can I access this control from my winform? If so then how? can u create a handler for that flash object?
回答1:
You can access the ActiveX's scripting interface from the element via the IHTMLObjectElement::object method. Search IShockwaveFlash in the microsoft.public.inetsdk.programming.webbrowser_ctl newsgroup for more information on this.
If you are using Windows Forms, html element's interface is exposed via HtmlElement.DomElement. You can add a reference to microsoft.mshtml and cast DomElement to IHTMLObjectElement, then obtain its object property and cast to IShockwaveFlash.
In ATL the code looks like this
#import "flash.dll" raw_interfaces_only
CComPtr<IDispatch> htmlElement;
CComPtr<IDispatch> activeXObject;
hr = GetElement(elementIdString, &htmlElement);
if (htmlElement!= NULL)
{
CComQIPtr<IHTMLObjectElement> htmlObjectElement(htmlElement);
if (htmlObjectElement!= NULL)
{
htmlObjectElement->get_object(&activeXObject);
CComQIPtr<ShockwaveFlashObjects::IShockwaveFlash, &IID_IUnknown> flashViewer(spdispActiveXObject);
if(flashViewer!=NULL)
{
//do something on the flash
CComBSTR movie;
flashViewer->get_Movie(&movie);
}
}
}
来源:https://stackoverflow.com/questions/2749394/flash-player-embedded-in-asp-page-which-is-opened-in-webbrowser-control