当前位置: 代码迷 >> .NET组件控件 >> winform如何自动关闭网页的alter警告窗口?
  详细解决方案

winform如何自动关闭网页的alter警告窗口?

热度:8659   发布时间:2013-02-25 00:00:00.0
winform怎么自动关闭网页的alter警告窗口???????
不输入账号时,点击登陆按钮,网页会弹出一个警告窗口,如下图。我想编程实现自动关闭这个警告窗口,怎么办??

我在网上找了下面的解决方案,:用FindWindow    (但试了,无效!不知道为什么?)

[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
        public const int WM_CLOSE = 0x10;


private void KillMessageBox()
        {
            //查找MessageBox的弹出窗口,注意对应标题
            IntPtr ptr = FindWindow(null, "来自网页的消息");
            if (ptr != IntPtr.Zero )
            {
   
                //查找到窗口则关闭
                PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
            }
        }

然后再调用KillMessageBox()


为什么这种方法不行呢??
------最佳解决方案--------------------------------------------------------
这是没问题的,你看看  FindWindow返回什么,或者用api的GetLastError看看是什么错误
------其他解决方案--------------------------------------------------------
重写网页的window.alert 方法
------其他解决方案--------------------------------------------------------
我将 if (ptr != IntPtr.Zero )写成if(true)也不行,说明 PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);这一句根本不起作用!
------其他解决方案--------------------------------------------------------
重写网页的window.alert 方法?菜鸟不会,能详细指点么??????
------其他解决方案--------------------------------------------------------
引用:
我将 if (ptr != IntPtr.Zero )写成if(true)也不行,说明 PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);这一句根本不起作用!


另外,网页源码中没有alert方法,我都不知道他的alter警告信息如何弹出来的
只找到一些隐藏表单<input type = "hidden" id="userNameNull"  value = "请输入用户名!"/>
  相关解决方案