Exemple #1
0
        public static WindowsApplication GetForeground()
        {
            IntPtr             foregroundHandle = WindowInvoker.GetForegroundWindow();
            WindowsApplication application      = new WindowsApplication(foregroundHandle);

            return(application);
        }
Exemple #2
0
        protected Bitmap GetScreenPortionAsImage(IntPtr displayContext, int positionX, int positionY, int width,
                                                 int height)
        {
            IntPtr displayCompatibleContext = WindowInvoker.CreateCompatibleDC(displayContext);
            IntPtr displayCompatibleBitmap  =
                WindowInvoker.CreateCompatibleBitmap(displayContext, width, height);

            // Select the new bitmap for future operations on our context
            IntPtr previousBitmap = WindowInvoker.SelectObject(displayCompatibleContext, displayCompatibleBitmap);

            // Copy the colour data from our desktop (and anything covering it) to our screenshot context
            bool isScreengrabSuccessful = WindowInvoker.BitBlt(displayCompatibleContext, 0, 0, width,
                                                               height, displayContext, positionX, positionY,
                                                               CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);

            Bitmap screenPortionImage = isScreengrabSuccessful ? Image.FromHbitmap(displayCompatibleBitmap) : null;

            // Restore our previous image selection
            WindowInvoker.SelectObject(displayCompatibleContext, previousBitmap);

            // Clean up our created objects so we're not hogging resources
            WindowInvoker.DeleteObject(displayCompatibleBitmap);
            WindowInvoker.DeleteDC(displayCompatibleContext);

            return(screenPortionImage);
        }
Exemple #3
0
        public Bitmap GetPortionAsImage(int positionX, int positionY, int width, int height)
        {
            IntPtr desktopContext = WindowInvoker.CreateDC("DISPLAY", null, null, IntPtr.Zero);

            Bitmap screenPortionImage = GetScreenPortionAsImage(desktopContext, positionX, positionY, width, height);

            WindowInvoker.DeleteDC(desktopContext);

            return(screenPortionImage);
        }
Exemple #4
0
        public Bitmap GetPortionAsImage(int positionX, int positionY, int width, int height)
        {
            IntPtr desktopContext = WindowInvoker.GetWindowDC(Handle);

            Bitmap screenPortionImage = GetScreenPortionAsImage(desktopContext, positionX, positionY, width, height);

            WindowInvoker.ReleaseDC(Handle, desktopContext);

            return(screenPortionImage);
        }
Exemple #5
0
        public Rectangle GetBounds()
        {
            int getAttributeResult = WindowInvoker.DwmGetWindowAttribute(Handle,
                                                                         DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS,
                                                                         out Interop.Structures.Rectangle applicationBounds, Marshal.SizeOf(typeof(Rectangle)));

            if (getAttributeResult != 0)
            {
                throw new WindowAttributeNotFoundException($"Could not find application boundaries for handle {Handle}", Handle);
            }

            Rectangle bounds = applicationBounds.AsDrawing();

            return(bounds);
        }
 private void SettingsCommandHandling()
 {
     WindowInvoker.ShowWindow(WindowInvoker.Windows.Settings);
 }
 private void PublicKeySettingsCommandHandling()
 {
     WindowInvoker.ShowWindow(WindowInvoker.Windows.PublicKeySettings);
 }
 private void CloseCommandHandling()
 {
     WindowInvoker.CloseWindows(WindowInvoker.Windows.PublicKeySettings);
 }
Exemple #9
0
 public WindowsScreen()
 {
     Handle = WindowInvoker.GetDesktopWindow();
 }