private static Rectangle GetWindowPlacement(IntPtr hWnd) { WindowRect rect = new WindowRect(); Win32Ext.GetWindowRect(hWnd, ref rect); return(rect); }
private static string GetWindowText(IntPtr hWnd) { int length = Win32Ext.GetWindowTextLength(hWnd) + 1; StringBuilder name = new StringBuilder(length); Win32Ext.GetWindowText(hWnd, name, length); return(name.ToString()); }
private static bool NeedSpecialCapturing(IntPtr hWnd) { if (Win32Ext.IsIconic(hWnd)) { return(true); } return(false); }
/// <summary> /// Get the collection of WindowSnap instances fro all available windows /// </summary> /// <param name="minimized">Capture a window even it's Minimized</param> /// <param name="specialCapturring">use special capturing method to capture minmized windows</param> /// <returns>return collections of WindowSnap instances</returns> public static WindowSnapCollection GetAllWindows(bool minimized, bool specialCapturring) { windowSnaps = new WindowSnapCollection(); countMinimizedWindows = minimized; //set minimized flag capture useSpecialCapturing = specialCapturring; //set specialcapturing flag Win32Ext.EnumWindowsCallbackHandler callback = new Win32Ext.EnumWindowsCallbackHandler(EnumWindowsCallback); Win32Ext.EnumWindows(callback, IntPtr.Zero); return(new WindowSnapCollection(windowSnaps.ToArray(), true)); }
private static void ExitSpecialCapturing(IntPtr hWnd) { Win32Ext.ShowWindow(hWnd, ShowWindowEnum.Minimize); Win32Ext.SetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE, winLong); if (minAnimateChanged) { XPAppearance.MinAnimate = true; minAnimateChanged = false; } }
private void EnterSpecialCapturing(IntPtr hWnd) { if (XPAppearance.MinAnimate) { XPAppearance.MinAnimate = false; minAnimateChanged = true; } winLong = Win32Ext.GetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE); Win32Ext.SetWindowLong(hWnd, Win32Ext.GWL_EXSTYLE, winLong | Win32Ext.WS_EX_LAYERED); Win32Ext.SetLayeredWindowAttributes(hWnd, 0, 1, Win32Ext.LWA_ALPHA); Win32Ext.ShowWindow(hWnd, ShowWindowEnum.Restore); Win32Ext.SendMessage(hWnd, Win32Ext.WM_PAINT, 0, 0); }
private static Bitmap GetWindowImage(IntPtr hWnd, Size size) { try { if (size.IsEmpty || size.Height < 0 || size.Width < 0) { return(null); } Bitmap bmp = new Bitmap(size.Width, size.Height); Graphics g = Graphics.FromImage(bmp); IntPtr dc = g.GetHdc(); Win32Ext.PrintWindow(hWnd, dc, 0); g.ReleaseHdc(); g.Dispose(); return(bmp); } catch { return(null); } }
private WindowSnap(IntPtr hWnd, bool specialCapturing) { Rectangle rect = GetWindowPlacement(hWnd); { this.IsMinimized = Win32Ext.IsIconic(hWnd); this.Handle = hWnd; this.Size = rect.Size; this.Location = rect.Location; this.Text = GetWindowText(hWnd); this.Image = GetWindowImage(hWnd, this.Size); } ChildSupport(hWnd); if (specialCapturing) { EnterSpecialCapturing(hWnd); } }
/// <summary> /// Child Window Support /// </summary> /// <param name="hWnd"></param> private void ChildSupport(IntPtr hWnd) { #region Condition initialize WindowInfo wInfo = new WindowInfo() { cbSize = WindowInfo.GetSize() }; Win32Ext.GetWindowInfo(hWnd, ref wInfo); IntPtr parent = Win32Ext.GetParent(hWnd); #endregion #region Condition if (!ForceMDICapturing || parent == IntPtr.Zero || (wInfo.dwExStyle & ExtendedWindowStyles.WS_EX_MDICHILD) != ExtendedWindowStyles.WS_EX_MDICHILD) { return; } StringBuilder name = new StringBuilder(); Win32Ext.GetClassName(parent, name, Win32Ext.RUNDLL.Length + 1); if (name.ToString() == Win32Ext.RUNDLL) { return; } #endregion #region Child Support Rectangle pos = GetWindowPlacement(hWnd); Win32Ext.MoveWindow(hWnd, int.MaxValue, int.MaxValue, pos.Width, pos.Height, true); Win32Ext.SetParent(hWnd, IntPtr.Zero); Win32Ext.SetParent(hWnd, parent); Rectangle parentPos = GetWindowPlacement(parent); int x = wInfo.rcWindow.Left - parentPos.X; int y = wInfo.rcWindow.Top - parentPos.Y; if ((wInfo.dwStyle & WindowStyles.WS_THICKFRAME) == WindowStyles.WS_THICKFRAME) { x -= SystemInformation.Border3DSize.Width; y -= SystemInformation.Border3DSize.Height; } Win32Ext.MoveWindow(hWnd, x, y, pos.Width, pos.Height, true); #endregion }
private static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam) { bool specialCapturing = false; if (hWnd == IntPtr.Zero) { return(false); } if (!Win32Ext.IsWindowVisible(hWnd)) { return(true); } if (!countMinimizedWindows) { if (Win32Ext.IsIconic(hWnd)) { return(true); } } else if (Win32Ext.IsIconic(hWnd) && useSpecialCapturing) { specialCapturing = true; } if (GetWindowText(hWnd) == Win32Ext.PROGRAMMANAGER) { return(true); } var Snap = new WindowSnap(hWnd, specialCapturing); if (!Snap.Text.Equals("")) { windowSnaps.Add(Snap); } return(true); }