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);
}
...