Example #1
0
        public string Execute()
        {
            string fileName = string.Empty;
            var    rect     = default(NativeMethods.RECT);

            Common.RestoreIfMinimized(_windowHandle);
            if (NativeMethods.GetWindowRect(_windowHandle, ref rect))
            {
                var region = NativeMethods.ConvertToRectangle(rect);
                using (var bitmap = new Bitmap(region.Width, region.Height, PixelFormat.Format32bppArgb))
                {
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        graphics.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);
                        if (Properties.Settings.Default.IncludeCursor)
                        {
                            Rectangle cursorBounds = new Rectangle(Cursor.Position, Cursor.Current.Size);
                            graphics.DrawIcon(CursorHelper.GetIcon(), cursorBounds);
                        }
                        fileName = Common.SaveImage(bitmap);
                    }
                }
            }
            return(fileName);
        }
        public string Execute()
        {
            Thread.Sleep(3000);
            string fileName = string.Empty;
            var    rect     = default(NativeMethods.RECT);

            _windowHandle = NativeMethods.GetForegroundWindow();
            IntPtr handle = _windowHandle == IntPtr.Zero ? NativeMethods.GetDesktopWindow() : _windowHandle;

            if (NativeMethods.GetWindowRect(handle, ref rect))
            {
                var region = NativeMethods.ConvertToRectangle(rect);
                using (var bitmap = new Bitmap(region.Width, region.Height, PixelFormat.Format32bppArgb))
                {
                    using (var graphics = Graphics.FromImage(bitmap))
                    {
                        graphics.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);
                        if (Properties.Settings.Default.IncludeCursor)
                        {
                            Rectangle cursorBounds = new Rectangle(Cursor.Position, Cursor.Current.Size);
                            graphics.DrawIcon(CursorHelper.GetIcon(), cursorBounds);
                        }
                        fileName = Common.SaveImage(bitmap);
                    }
                }
            }
            return(fileName);
        }