コード例 #1
0
ファイル: SpyWindow.cs プロジェクト: frk2/Scraperwin
        /// <summary>
        /// Handles all mouse move messages sent to the Spy Window
        /// </summary>
        private void HandleMouseMovements()
        {
            // if we're not capturing, then bail out
            if (!_capturing)
            {
                return;
            }

            try
            {
                // capture the window under the cursor's position
                IntPtr hWnd = Win32.WindowFromPoint(Cursor.Position);

                // if the window we're over, is not the same as the one before, and we had one before, refresh it
                if (_hPreviousWindow != IntPtr.Zero && _hPreviousWindow != hWnd)
                {
                    WindowHighlighter.Refresh(_hPreviousWindow);
                }

                // if we didn't find a window.. that's pretty hard to imagine. lol
                if (hWnd == IntPtr.Zero)
                {
                    _textBoxHandle.Text = null;
                    _textBoxClass.Text  = null;
                    _textBoxText.Text   = null;
                    _textBoxStyle.Text  = null;
                    _textBoxRect.Text   = null;
                }
                else
                {
                    // save the window we're over
                    _hPreviousWindow = hWnd;

                    // handle
                    _textBoxHandle.Text = string.Format("{0}", hWnd.ToInt32().ToString());

                    // class
                    _textBoxClass.Text = this.GetClassName(hWnd);

                    // caption
                    _textBoxText.Text = this.GetWindowText(hWnd);

                    Win32.Rect rc = new Win32.Rect();
                    Win32.GetWindowRect(hWnd, ref rc);

                    // rect
                    _textBoxRect.Text = string.Format("[{0} x {1}], ({2},{3})-({4},{5})", rc.right - rc.left, rc.bottom - rc.top, rc.left, rc.top, rc.right, rc.bottom);

                    // highlight the window
                    WindowHighlighter.Highlight(hWnd);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #2
0
        /// <summary>
        /// Highlights the specified window just like Spy++
        /// </summary>
        /// <param name="hWnd"></param>
        public static void Highlight(IntPtr hWnd)
        {
            const float penWidth = 3;
            Win32.Rect rc = new Win32.Rect();
            Win32.GetWindowRect(hWnd, ref rc);

            IntPtr hDC = Win32.GetWindowDC(hWnd);
            if (hDC != IntPtr.Zero)
            {
                using (Pen pen = new Pen(Color.Black, penWidth))
                {
                    using (Graphics g = Graphics.FromHdc(hDC))
                    {
                        g.DrawRectangle(pen, 0, 0, rc.right - rc.left - (int)penWidth, rc.bottom - rc.top - (int)penWidth);
                    }
                }
            }
            Win32.ReleaseDC(hWnd, hDC);
        }
コード例 #3
0
        /// <summary>
        /// Gets a Bitmap of the window (aka. screen capture)
        /// </summary>
        public static Bitmap GetWindowCaptureAsBitmap(int handle)
        {
            IntPtr hWnd = new IntPtr(handle);

            Win32.Rect rc = new Win32.Rect();
            if (!Win32.GetWindowRect(hWnd, ref rc))
            {
                return(null);
            }

//			Win32.WindowInfo wi = new Win32.WindowInfo();
//			wi.size = Marshal.SizeOf(wi);
//			if (!Win32.GetWindowInfo(hWnd, ref wi))
//				return null;

            // create a bitmap from the visible clipping bounds of the graphics object from the window
            Bitmap bitmap = new Bitmap(rc.Width, rc.Height);

            // create a graphics object from the bitmap
            Graphics gfxBitmap = Graphics.FromImage(bitmap);

            // get a device context for the bitmap
            IntPtr hdcBitmap = gfxBitmap.GetHdc();

            // get a device context for the window
            IntPtr hdcWindow = Win32.GetWindowDC(hWnd);

            // bitblt the window to the bitmap
            Win32.BitBlt(hdcBitmap, 0, 0, rc.Width, rc.Height, hdcWindow, 0, 0, (int)Win32.TernaryRasterOperations.SRCCOPY);

            // release the bitmap's device context
            gfxBitmap.ReleaseHdc(hdcBitmap);

            Win32.ReleaseDC(hWnd, hdcWindow);

            // dispose of the bitmap's graphics object
            gfxBitmap.Dispose();

            // return the bitmap of the window
            return(bitmap);
        }
コード例 #4
0
ファイル: WindowHighlighter.cs プロジェクト: frk2/Scraperwin
        /// <summary>
        /// Highlights the specified window just like Spy++
        /// </summary>
        /// <param name="hWnd"></param>
        public static void Highlight(IntPtr hWnd)
        {
            const float penWidth = 3;

            Win32.Rect rc = new Win32.Rect();
            Win32.GetWindowRect(hWnd, ref rc);

            IntPtr hDC = Win32.GetWindowDC(hWnd);

            if (hDC != IntPtr.Zero)
            {
                using (Pen pen = new Pen(Color.Black, penWidth))
                {
                    using (Graphics g = Graphics.FromHdc(hDC))
                    {
                        g.DrawRectangle(pen, 0, 0, rc.right - rc.left - (int)penWidth, rc.bottom - rc.top - (int)penWidth);
                    }
                }
            }
            Win32.ReleaseDC(hWnd, hDC);
        }
コード例 #5
0
ファイル: SpyWindow.cs プロジェクト: sczk/collab-project
        /// <summary>
        /// Handles all mouse move messages sent to the Spy Window
        /// </summary>
        private void HandleMouseMovements()
        {
            // if we're not capturing, then bail out
            if (!_capturing)
                return;

            try
            {
                // capture the window under the cursor's position
                IntPtr hWnd = Win32.WindowFromPoint(Cursor.Position);

                // if the window we're over, is not the same as the one before, and we had one before, refresh it
                if (_hPreviousWindow != IntPtr.Zero && _hPreviousWindow != hWnd)
                    WindowHighlighter.Refresh(_hPreviousWindow);

                // if we didn't find a window.. that's pretty hard to imagine. lol
                if (hWnd == IntPtr.Zero)
                {
                    _textBoxHandle.Text = null;
                    _textBoxClass.Text = null;
                    _textBoxText.Text = null;
                    _textBoxStyle.Text = null;
                    _textBoxRect.Text = null;
                }
                else
                {
                    // save the window we're over
                    _hPreviousWindow = hWnd;

                    // handle
                    _textBoxHandle.Text = string.Format("{0}", hWnd.ToInt32().ToString());

                    // class
                    _textBoxClass.Text = this.GetClassName(hWnd);

                    // caption
                    _textBoxText.Text = this.GetWindowText(hWnd);

                    Win32.Rect rc = new Win32.Rect();
                    Win32.GetWindowRect(hWnd, ref rc);

                    // rect
                    _textBoxRect.Text = string.Format("[{0} x {1}], ({2},{3})-({4},{5})", rc.right - rc.left, rc.bottom - rc.top, rc.left, rc.top, rc.right, rc.bottom);

                    // highlight the window
                    WindowHighlighter.Highlight(hWnd);
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets a Bitmap of the window (aka. screen capture)
        /// </summary>
        public static Bitmap GetWindowCaptureAsBitmap(int handle)
        {
            IntPtr hWnd = new IntPtr(handle);
            Win32.Rect rc = new Win32.Rect();
            if (!Win32.GetWindowRect(hWnd, ref rc))
                return null;

            //			Win32.WindowInfo wi = new Win32.WindowInfo();
            //			wi.size = Marshal.SizeOf(wi);
            //			if (!Win32.GetWindowInfo(hWnd, ref wi))
            //				return null;

            // create a bitmap from the visible clipping bounds of the graphics object from the window
            Bitmap bitmap = new Bitmap(rc.Width, rc.Height);

            // create a graphics object from the bitmap
            Graphics gfxBitmap = Graphics.FromImage(bitmap);

            // get a device context for the bitmap
            IntPtr hdcBitmap = gfxBitmap.GetHdc();

            // get a device context for the window
            IntPtr hdcWindow = Win32.GetWindowDC(hWnd);

            // bitblt the window to the bitmap
            Win32.BitBlt(hdcBitmap, 0, 0, rc.Width, rc.Height, hdcWindow, 0, 0, (int)Win32.TernaryRasterOperations.SRCCOPY);

            // release the bitmap's device context
            gfxBitmap.ReleaseHdc(hdcBitmap);

            Win32.ReleaseDC(hWnd, hdcWindow);

            // dispose of the bitmap's graphics object
            gfxBitmap.Dispose();

            // return the bitmap of the window
            return bitmap;
        }