Esempio n. 1
0
 public void MoveWindows()
 {
     foreach (Process prc in _openWindows)
     {
         if (prc.ProcessName == "explorer")
         {
             User32.Rect rc = new User32.Rect();
             User32.GetWindowRect(prc.MainWindowHandle, ref rc);
         }
         User32.SetWindowPos(prc.MainWindowHandle, IntPtr.Zero, 0, 0, 0, 0, User32.SetWindowPosFlags.DoNotChangeOwnerZOrder | User32.SetWindowPosFlags.IgnoreResize);
     }
 }
Esempio n. 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //Premature check if our process is closed -> stop the mirror!
                if (_mirrorState.SelectedProcess.HasExited)
                {
                    StopMirroring();
                }

                if (GetProcessFromActiveWindow().Id == _mirrorState.SelectedProcess.Id)
                {
                    _openWindows.Clear();
                    GetDesktopWindowsTitlesToPrivateVar();

                    User32.Rect rc = new User32.Rect();
                    User32.GetWindowRect(_mirrorState.SelectedProcess.MainWindowHandle, ref rc);


                    if (!_mirrorState.SelectedProcess.HasExited || _openWindows.Contains(_mirrorState.SelectedProcess))
                    {
                        var placement = GetPlacement(_mirrorState.SelectedProcess.MainWindowHandle);

                        if (_mirrorState.MirrorType == MirrorState.MirrorTypes.Screenshot && placement.showCmd == User32.ShowWindowCommands.Normal)
                        {
                            User32.ShowWindow(_mirrorState.SelectedProcess.MainWindowHandle, User32.SW_SHOW);
                            User32.ShowWindow(_mirrorState.SelectedProcess.MainWindowHandle, User32.SW_SHOWMAXIMIZED);
                        }
                        DrawImageToForm();
                    }
                    else
                    {
                        StopMirroring();
                    }
                }
            }
            catch { }
        }
Esempio n. 3
0
        public Bitmap CaptureApplication(Process proc)
        {
            try
            {
                Bitmap bmpScreenshot = null;
                if (_defaultScreenshotWindows.Contains(_mirrorState.SelectedProcess.ProcessName.ToLower()))
                {
                    var placement = GetPlacement(_mirrorState.SelectedProcess.MainWindowHandle);

                    if (placement.showCmd == User32.ShowWindowCommands.Normal)
                    {
                        User32.ShowWindowAsync(_mirrorState.SelectedProcess.MainWindowHandle, User32.SW_SHOWMAXIMIZED);
                    }

                    bmpScreenshot = new Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height - 25, PixelFormat.Format32bppArgb);
                    var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
                    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.WorkingArea.X, Screen.PrimaryScreen.WorkingArea.Y + 25, 0, 0, Screen.PrimaryScreen.WorkingArea.Size, CopyPixelOperation.SourceCopy);
                }
                else
                {
                    try
                    {
                        User32.Rect rct = new User32.Rect();
                        User32.GetWindowRect(_mirrorState.SelectedProcess.MainWindowHandle, ref rct);

                        bmpScreenshot = new Bitmap(rct.right - rct.left, rct.bottom - rct.top);

                        Graphics memoryGraphics = Graphics.FromImage(bmpScreenshot);

                        IntPtr dc      = memoryGraphics.GetHdc();
                        bool   success = User32.PrintWindow(_mirrorState.SelectedProcess.MainWindowHandle, dc, 1);
                        memoryGraphics.ReleaseHdc(dc);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.ToString());
                    }
                }

                //Mouse addition by http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display=Print
                int       cursorX = 0;
                int       cursorY = 0;
                Bitmap    desktopBMP;
                Bitmap    cursorBMP;
                Graphics  g;
                Rectangle r;

                desktopBMP = bmpScreenshot;

                cursorBMP = CaptureCursor(ref cursorX, ref cursorY);
                if (desktopBMP != null)
                {
                    if (cursorBMP != null)
                    {
                        r = new Rectangle(cursorX, cursorY, cursorBMP.Width, cursorBMP.Height);
                        g = Graphics.FromImage(desktopBMP);
                        g.DrawImage(cursorBMP, r);
                        g.Flush();

                        GC.Collect();

                        return(desktopBMP);
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(null);
            }
        }