public const int WM_CLOSE = 0x10;
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public static void CloseProcessByName(string lpWindowName)
{
IntPtr hwnd_win; hwnd_win = FindWindow(null, lpWindowName);//lpWindowName "要找的表單名稱"
SendMessage(hwnd_win, WM_CLOSE, 0, 0);
}
API關閉指定表單
最新推荐文章于 2025-06-16 22:16:44 发布
