Esempio n. 1
0
        /// <summary>
        /// Takes screenshot of the window (supports multiple monitors) and then lets user to select the wanted area and returns that area.
        /// Also returns the rectangle of the selected part inside of the window.
        /// </summary>
        public static Image Snip(IntPtr hWnd, out Rectangle rect, PixelFormat format = PixelFormat.Format24bppRgb)
        {
            NativeWin32.SetForegroundWindow(hWnd);

            Rect r;

            if (!NativeWin32.GetWindowRect(hWnd, out r))
            {
                rect = Rectangle.Empty;
                return(null);
            }
            rect = new Rectangle(Convert.ToInt32(r.X), Convert.ToInt32(r.Y), Convert.ToInt32(r.Width), Convert.ToInt32(r.Height));

            var bmp = ScreenShot.Create(hWnd);

            Graph = Graphics.FromImage(bmp);
            Graph.SmoothingMode = SmoothingMode.None;

            using (var snipper = new SnippingTool(bmp)
            {
                SpecificWindowMode = true
            }) {
                snipper.Location = new Point(rect.Left, rect.Top);
                NativeWin32.SetForegroundWindow(snipper.Handle);

                if (snipper.ShowDialog() == DialogResult.OK)
                {
                    rect = snipper.rcSelect;
                    return(snipper.Image);
                }
            }
            rect = Rectangle.Empty;
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        ///     Create a complete screenshot of a window by using a handle.
        /// </summary>
        /// <param name="windowHandle">
        ///     Handle of the window.
        /// </param>
        /// <returns>
        ///     A <see cref="Bitmap"/> of the window.
        /// </returns>
        public static Bitmap Create(IntPtr windowHandle)
        {
            Rect window;

            NativeWin32.GetWindowRect(windowHandle, out window);
            int       winWidth   = Convert.ToInt32(window.Right - window.Left);
            int       winHeight  = Convert.ToInt32(window.Bottom - window.Top);
            Rectangle windowRect = new Rectangle((int)window.Left, (int)window.Top, winWidth, winHeight);
            Bitmap    bmpScreen  = ScreenShot.Create(windowRect);

            return(bmpScreen);
        }
Esempio n. 3
0
        private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0 && (wParam == (IntPtr)WM_KEYDOWN || wParam == (IntPtr)WM_SYSKEYDOWN))
            {
                Keys number = (Keys)Marshal.ReadInt32(lParam);

                string cucc = nCode.ToString() + " | " +
                              wParam.ToString() + " | " +
                              lParam.ToString() + " | " +
                              number.ToString() + " | " +
                              Control.ModifierKeys.ToString();

                if (number == Keys.PrintScreen)
                {
                    if ((wParam == (IntPtr)256 && number == Keys.PrintScreen && Keys.None == Control.ModifierKeys))
                    {
                        System.Threading.Thread fullps = new System.Threading.Thread(() => new ScreenMode.FullScreen());
                        fullps.SetApartmentState(System.Threading.ApartmentState.STA);
                        fullps.Start();
                    }
                    else if ((wParam == (IntPtr)260 && Keys.Alt == Control.ModifierKeys && number == Keys.PrintScreen))
                    {
                        IntPtr    hWnd = NativeWin32.GetForegroundWindow();
                        Rectangle rect;
                        NativeWin32.GetWindowRect(hWnd, out rect);
                        new Thread(() => new ScreenMode.ActiveWindow(rect)).Start();
                    }
                    else if ((wParam == (IntPtr)256 && Keys.Control == Control.ModifierKeys && number == Keys.PrintScreen))
                    {
                        DesignateArea secondForm = new DesignateArea();
                        secondForm.Show();
                    }
                }
            }
            return(NativeWin32.CallNextHookEx(_hookID, nCode, wParam, lParam));
        }