winform怎么自动关闭网页的alter警告窗口???????

布里渊区 2012-11-30 11:02:35
不输入账号时,点击登陆按钮,网页会弹出一个警告窗口,如下图。我想编程实现自动关闭这个警告窗口,怎么办??

我在网上找了下面的解决方案,:用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()


为什么这种方法不行呢??
...全文
255 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
SaDanFengGe 2012-12-25
  • 打赏
  • 举报
回复
这个问题解决了没有?
布里渊区 2012-11-30
  • 打赏
  • 举报
回复
引用 2 楼 cctvcqupt 的回复:
我将 if (ptr != IntPtr.Zero )写成if(true)也不行,说明 PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);这一句根本不起作用!
另外,网页源码中没有alert方法,我都不知道他的alter警告信息如何弹出来的 只找到一些隐藏表单<input type = "hidden" id="userNameNull" value = "请输入用户名!"/>
布里渊区 2012-11-30
  • 打赏
  • 举报
回复
重写网页的window.alert 方法?菜鸟不会,能详细指点么??????
马老虎 2012-11-30
  • 打赏
  • 举报
回复
重写网页的window.alert 方法
布里渊区 2012-11-30
  • 打赏
  • 举报
回复
我将 if (ptr != IntPtr.Zero )写成if(true)也不行,说明 PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);这一句根本不起作用!
bdmh 2012-11-30
  • 打赏
  • 举报
回复
这是没问题的,你看看 FindWindow返回什么,或者用api的GetLastError看看是什么错误

8,834

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 组件/控件开发
社区管理员
  • 组件/控件开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧