public Bitmap GetScreenshtOfSelectedWindow(IntPtr handle)
        {
            Contract.Requires(handle != IntPtr.Zero);

            SSWindowsFunctions.RefreshWindow(handle);

            SSWindowsFunctions.RECT rc = new SSWindowsFunctions.RECT();

            SSWindowsFunctions.GetWindowRect(handle, out rc);
            var bound = new Rectangle(rc.Left,rc.Top,rc.Right - rc.Left,rc.Bottom - rc.Top);
            var result = new Bitmap(bound.Width,bound.Height);

            using (var graphics = Graphics.FromImage(result))
            {
                graphics.CopyFromScreen(new Point(bound.Left,bound.Top),Point.Empty,bound.Size);
            }
            return result;
        }
Exemple #2
0
        private static void HighlightingCurrentWindow(IntPtr hWnd)
        {
            SSWindowsFunctions.RECT rc = new SSWindowsFunctions.RECT();

            SSWindowsFunctions.GetWindowRect(hWnd, out rc);
            var hDC = SSWindowsFunctions.GetWindowDC(hWnd);

            if (hDC != IntPtr.Zero)
            {
                using (var graphics = Graphics.FromHdc(hDC))
                {
                    var pen = new Pen(Color.Red,3);
                    graphics.DrawRectangle(pen,0,0, rc.Right - rc.Left,rc.Bottom - rc.Top);
                }
                SSWindowsFunctions.ReleaseDC(hWnd, hDC);
            }
            
        }