调用API 查找到窗体 并关闭

 [DllImport("user32.dll", EntryPoint = "SendMessage")]
    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 const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE = 0xF060;
        void CloseDownload()
        {
            IntPtr hwnd = FindWindow(null, "下载完毕");
            if (hwnd == IntPtr.Zero)
            {
                return;
            }
            SendMessage(hwnd, WM_SYSCOMMAND, (IntPtr)SC_CLOSE, 0);
        }

你可能感兴趣的:(C#)