不输入账号时,点击登陆按钮,网页会弹出一个警告窗口,如下图。我想编程实现自动关闭这个警告窗口,怎么办??
我在网上找了下面的解决方案,:用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()
为什么这种方法不行呢??