因为需要,为了结束其它程序窗口,我简单封装了一个方法,用于

结束掉其它程序的广告窗口,文章后面附有该源文件的下载地址和使用方法。

--------------------------------------------------------------------------------------

主要代码如下:

    class Win32API
    {
        [DllImport("User32.dll ")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent,
                                                 IntPtr hwndChild, 
                                                 string wndClassName, 
                                                 string wndName
                                                );
        [DllImport("User32.dll ",EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, 
                                             int wMsg, 
                                             int lParam, 
                                             int wParam
                                            );
        [DllImport("User32.dll",EntryPoint = "PostMessage")]
        public static extern int PostMessage(IntPtr hwnd,
                                             int wMsg,
                                             int lParam,
                                             int wParam
                                            );
        /// <summary>
        /// 关闭指定窗口
        /// </summary>
        /// <param name="wndClassName">窗口的类名</param>
        /// <param name="wndCaption">窗口的标题</param>
        /// <returns></returns>
        public static void CloseWindow(string wndClassName,string wndCaption)
        {
            //查找窗口
            IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, wndClassName, wndCaption);
            
            //关闭窗口
            const int WM_CLOSE = 0x10;
            //SendMessage(hWnd,WM_CLOSE,0,0);
            PostMessage(hWnd, WM_CLOSE,0,0);

        }
    }
---------------------------------------------------------------------------------------------------------------------------------------------------------

  源码文件下载地址:    C#结束其它程序窗口源码.zip   //免积分

                   备份地址:  C#结束其它程序窗口源码.zip    //需积分

----------------------------------------------------------------------------------------------------------------------------------------------------------


您的十分满意是我追求的宗旨。

您的一点建议是我后续的动力。








本文转载:CSDN博客