NavigateComplete、DocumentComplete 等工作得很好,但由于某种原因 WindowStateChanged 不能。我正在使用 IE9 进行测试。这个活动被取消了吗?
public class BHO : IObjectWithSite, IOleCommandTarget
{
IWebBrowser2 browser = null;
int version = 9;
void OnNavigateComplete2(object pDisp, ref object URL)
{
if (!ReferenceEquals(pDisp, browser))
{
}
else
{
var document = browser.Document as IHTMLDocument2;
var window = document.parentWindow;
Debug.WriteLine(version + "MainURL: " + URL.ToString());
}
}
void OnWindowStateChanged(uint dwWindowStateFlags, uint dwValidFlagsMask)
{
version = version * 2; //never hit
Debug.WriteLine(version);
}
#region Implementation of IObjectWithSite
int IObjectWithSite.SetSite(object site)
{
Debug.WriteLine("SetSite!");
if (site != null)
{
browser = (IWebBrowser2)site;
((DWebBrowserEvents2_Event)browser).NavigateComplete2 +=
new WebBrowserEvents2_NavigateComplete2EventHandler
(this.OnNavigateComplete2);
((DWebBrowserEvents2_Event)browser).WindowStateChanged +=
new WebBrowserEvents2_WindowStateChangedEventHandler
(this.OnWindowStateChanged);
}
...