/* void GetClientRect() * client rect: the web page rect, not include menu, address bar ect. */ protected void GetClientRect() { if (_rootHandle != IntPtr.Zero) { _shellDocHandle = WindowsAsstFunctions.GetShellDocHandle(_rootHandle); if (_shellDocHandle != IntPtr.Zero) { _ieServerHandle = WindowsAsstFunctions.GetIEServerHandle(_shellDocHandle); if (_ieServerHandle != IntPtr.Zero) { try { Win32API.Rect tmpRect = new Win32API.Rect(); if (Win32API.GetWindowRect(_ieServerHandle, ref tmpRect)) { _clientLeft = tmpRect.left; _clientTop = tmpRect.top; _clientWidth = tmpRect.Width; _clientHeight = tmpRect.Height; return; } } catch (TestException) { throw; } catch (Exception ex) { throw new CannotAttachBrowserException("Can not get client size of test browser: " + ex.ToString()); } } } } throw new BrowserNotFoundException("Can not get handles of test browser"); }
public static Rect GetWindowRect(IntPtr hwnd) { Win32API.Rect rect = new Win32API.Rect(); Win32API.GetWindowRect(hwnd, ref rect); return rect; }
/* Image CaptureWindow(IntPtr handle) * return an image of expected handle. */ public static Image CaptureWindow(IntPtr handle) { try { if (handle == IntPtr.Zero) { throw new Exception("Handle can not be 0."); } // get the size Win32API.Rect windowRect = new Win32API.Rect(); Win32API.GetWindowRect(handle, ref windowRect); int width = windowRect.right - windowRect.left; int height = windowRect.bottom - windowRect.top; if (width > 0 && height > 0) { bool printed = false; //firstly, try PrintWindow to get the image of the window. Bitmap bm = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(bm)) { System.IntPtr bmDC = g.GetHdc(); printed = Win32API.PrintWindow(handle, bmDC, 0); g.ReleaseHdc(bmDC); } if (printed) { return bm; } else { //not printed, try other way. // get te hDC of the target window IntPtr hdcSrc = Win32API.GetWindowDC(handle); // create a device context we can copy to IntPtr hdcDest = Win32API.CreateCompatibleDC(hdcSrc); // create a bitmap we can copy it to, IntPtr hBitmap = Win32API.CreateCompatibleBitmap(hdcSrc, width, height); // select the bitmap object IntPtr hOld = Win32API.SelectObject(hdcDest, hBitmap); // bitblt over Win32API.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, Win32API.SRCCOPY); // restore selection Win32API.SelectObject(hdcDest, hOld); // clean up Win32API.DeleteDC(hdcDest); Win32API.ReleaseDC(handle, hdcSrc); // get a .NET image object for it Image img = Image.FromHbitmap(hBitmap); // free up the Bitmap object Win32API.DeleteObject(hBitmap); return img; } } else { throw new Exception("Can not get size infomation of the window."); } } catch (Exception ex) { throw new Exception(ex.ToString()); } }
public static void RestoreHighLight(Win32API.Rect rect, IntPtr handle) { Win32API.Rect invalidRect = new Win32API.Rect(); invalidRect.left = rect.left - Hight_Border; invalidRect.top = rect.top - Hight_Border; invalidRect.right = rect.right + Hight_Border; invalidRect.bottom = rect.bottom + Hight_Border; //refresh the window Win32API.InvalidateRect(handle, ref invalidRect, 1); //Win32API.UpdateWindow(handle); }
public static void RestoreHighLight(int left, int top, int width, int height, IntPtr handle) { if (handle == IntPtr.Zero) { handle = Win32API.WindowFromPoint(left + width / 2, top + height / 2); } Win32API.Rect rect = new Win32API.Rect(); rect.left = left; rect.top = top; rect.right = left + width; rect.bottom = top + height; RestoreHighLight(rect, handle); }
public static void HighlightScreenRect(int left, int top, int width, int height, int mseconds) { IntPtr handle = Win32API.WindowFromPoint(left + width / 2, top + height / 2); Win32API.Rect windRect = new Win32API.Rect(); Win32API.GetWindowRect(handle, ref windRect); left -= windRect.left; top -= windRect.top; HighlightWindowRect(handle, left, top, width, height, mseconds); }
public System.Drawing.Rectangle GetRectOnScreen() { try { Win32API.Rect rect = new Win32API.Rect(); Win32API.GetWindowRect(this.Handle, ref rect); this._left = rect.left; this._top = rect.top; this._width = rect.Width; this._height = rect.Height; return new System.Drawing.Rectangle(_left, _top, _width, _height); } catch (Exception ex) { throw new CannotGetAppInfoException("Can not get size of test app: " + ex.ToString()); } }