/// <summary> /// 根据类名和窗口名获取句柄 /// </summary> /// <param name="lpClassName"></param> /// <param name="lpWindowName"></param> /// <returns></returns> [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); /// <summary> /// 给窗口发送消息 /// </summary> /// <param name="hwnd"></param> /// <param name="wMsg"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private void button1_Click(object sender, EventArgs e) { IntPtr str = FindWindow("#32770", "CmIDCard"); SendMessage(str, 0x10, 0, 0);//关闭窗体 }