1、引包
[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;
2、方法
IntPtr ptr = FindWindow(null, "error");
if (ptr != IntPtr.Zero)
{
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}