webBrowser之取消重新傳送對話框

C# 使用WIN32API須先引入

http://msdn.microsoft.com/zh-tw/library/ms171548.aspx

using System.Runtime.InteropServices;

 在主程式加入API函數

      
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, int hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern int GetDlgCtrlID(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
private const int WM_COMMAND = 0x111;

使用一個TIMER去偵測 webBrowser是否有跳出整理視窗

private void timer1_Tick(object sender, EventArgs e){
 IntPtr hWnd = FindWindow("#32770", "Windows Internet Explorer");
            if (!hWnd.Equals(IntPtr.Zero)){
                IntPtr hButton = FindWindowEx(hWnd, 0, "BUTTON", "重試(&R)");
                if (!hButton.Equals(IntPtr.Zero)){
                    SendMessage(hWnd, WM_COMMAND, GetDlgCtrlID(hButton), hButton);
                }
            }
          }

相關文章:

  1. SendMessage VS PostMessage
  2. [wm]通訊錄存取
  3. [C#]修改ACCESS密碼
  4. [wm]使用TryParse

FaceBook留言板

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>