首页 新闻 会员 周边

Process.MainWindowHandle抛出的奇怪异常

0
[已关闭问题]

InternetExplorer ie = null;

        public InternetExplorer LaunchIE()
        {
            Process p = Process.Start("iexplore.exe", "about:blank");
            //SetForegroundWindow(p.MainWindowHandle);

            if (p == null)
            {
                throw new Exception("Could not launch IE");
            }

            ShellWindows allBrowser = new ShellWindows();

            if (allBrowser.Count == 0)
            {
                throw new Exception("Can not find IE");
            }

            Int32 i = 0;
            while (i < allBrowser.Count && ie == null)
            {
                InternetExplorer e = (InternetExplorer)allBrowser.Item(i);

                if (e.HWND == (int)p.MainWindowHandle)
                {
                    ie = e;
                }

                i++;
            }

            return ie;
        }

 

各位高人,小D以上的代码,这里if (e.HWND == (int)p.MainWindowHandle)
抛出这个异常:

Specified cast is not valid.

 照书抄的..不知道为什么会出这个异常.

希望各位高人能抽空帮忙回答下,拜谢!

平台:Windows Vista 6001, VS 2008, .NET Framework 3.5

ChrisWang的主页 ChrisWang | 初学一级 | 园豆:200
提问于:2009-02-04 16:48
< >
分享
其他回答(1)
0

我试了在我电脑是没有问题,你是IE7吧。

估计是IE7与6有不同,至于具体的,暂不清楚。

你可以看看e.HWND在IE7与IE6在含义或表示上的区别。

hackenliu | 园豆:600 (小虾三级) | 2009-02-04 17:24
0

看看下面这个链接,看对你有没有帮助

http://www.bokebb.com/dev/english/1936/posts/193610338.shtml

eaglet | 园豆:17139 (专家六级) | 2009-02-05 06:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册