這個有好多用途阿,像是WebBrowser跳出JavaScript的Alert視窗後可把它關了\ . /"
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int FindWindowEx(int hw,IntPtr hw2,string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern long SendMessage(int hWnd,uint Msg);
public const uint WM_LBUTTONUP = 0x0202;
public const uint WM_LBUTTONDOWN = 0x0201;
===========================================================
string ClassName ="";
string WindowName ="";
int alertHandle = 0;
int childHandle = 0;
ClassName = "#32770";
WindowName = "網頁訊息";
alertHandle = FindWindow(ClassName, WindowName);
if (alertHandle != 0)
{
label1.Text = "找到ClassName為" + ClassName + "且WindowName為" + WindowName + "的視窗";
childHandle=FindWindowEx(alertHandle, IntPtr.Zero, "Button", "確定");
SendMessage(chileHandle, WM_LBUTTONDOWN);
SendMessage(chileHandle, WM_LBUTTONUP);
}
else
{
label1.Text = "找不到ClassName為" + ClassName + "且WindowName為" + WindowName + "的視窗";
}
如果有文字"是"跟"否"有底線那種的話,就用
是(&Y)
否(&N)