//显示/隐藏所有进程相关的窗体(如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); } }
//获取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); }
//获取打开的窗体列表 public static List <WindowInfo> GetHandleList(int Handle) { List <WindowInfo> fromInfo = new List <WindowInfo>(); try { int handle = Win32API.GetWindow(Handle, Win32API.GW_HWNDFIRST); while (handle > 0) { int IsTask = Win32API.WS_VISIBLE | Win32API.WS_BORDER | Win32API.WS_MAXIMIZEBOX;//窗体可见、有边框、有最大化按钮 //int IsTask = Win32API.WS_VISIBLE ;//窗体可见 int lngStyle = Win32API.GetWindowLongA(handle, Win32API.GWL_STYLE); bool TaskWindow = ((lngStyle & IsTask) == IsTask); if (TaskWindow) { int length = Win32API.GetWindowTextLength(new IntPtr(handle)); StringBuilder stringBuilder = new StringBuilder(2 * length + 1); Win32API.GetWindowText(handle, stringBuilder, stringBuilder.Capacity); string strTitle = stringBuilder.ToString(); if (!string.IsNullOrEmpty(strTitle)) { fromInfo.Add(new WindowInfo(strTitle, (IntPtr)handle)); } else { fromInfo.Add(new WindowInfo("无标题", (IntPtr)handle)); } } handle = Win32API.GetWindow(handle, Win32API.GW_HWNDNEXT); } } catch (Exception ex) { LogManage.WriteLog(typeof(WindowHide), ex); } return(fromInfo); }