예제 #1
0
        //显示/隐藏所有进程相关的窗体(如QQ)
        public static void SetWindowVisible(IntPtr owner, bool visible)
        {
            try
            {
                //const string CLASS_PARENT = "TXGuiFoundation";
                //const string CLASS_CHILD = "ATL:006CC4D0";

                //窗体的子窗体
                //IntPtr p = Win32API.FindWindowEx(owner, IntPtr.Zero, CLASS_CHILD, string.Empty);

                StringBuilder title     = new StringBuilder(256);
                StringBuilder className = new StringBuilder(256);

                Win32API.GetWindowText(owner.ToInt32(), title, title.Capacity);//得到窗口的标题

                if (title.ToString().Trim() != "")
                {
                    Win32API.GetClassName(owner, className, className.Capacity);
                }

                Win32API.ShowWindow(owner, visible ? Win32API.SW_SHOW : Win32API.SW_HIDE);

                //显示/隐藏托盘图标
                WindowHide.SetTrayIconVisible(title.ToString(), visible);
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(WindowHide), ex);
            }
        }
예제 #2
0
        //获取MSN窗体列表
        public static List <WindowInfo> GetMSNWindowList(int Handle)
        {
            List <WindowInfo> list = new List <WindowInfo>();

            try
            {
                const string CLASS_PARENT = "IMWindowClass";
                const string CLASS_CHILD  = "IM Window Native WindowBar Class";



                StringBuilder title     = new StringBuilder(256);
                StringBuilder className = new StringBuilder(256);

                int h = Handle;// (int)Win32API.FindWindow(CLASS_PARENT, "");
                while (h != 0)
                {
                    //窗体的子窗体
                    IntPtr p = Win32API.FindWindowEx(new IntPtr(h), IntPtr.Zero, CLASS_CHILD, "");

                    if (p != IntPtr.Zero)
                    {
                        Win32API.GetWindowText(h, title, title.Capacity);//得到窗口的标题

                        if (title.ToString().Trim() != "")
                        {
                            Win32API.GetClassName(new IntPtr(h), className, className.Capacity);
                        }

                        if (className.ToString().Trim() != "" && className.ToString() == CLASS_PARENT)
                        {
                            WindowInfo wi = new WindowInfo(title.ToString(), new IntPtr(h));
                            list.Add(wi);
                        }
                    }
                    h = Win32API.GetWindow(h, Win32API.GW_HWNDNEXT);
                }
            }
            catch (Exception ex)
            {
                LogManage.WriteLog(typeof(WindowHide), ex);
            }
            return(list);
        }