Ejemplo n.º 1
0
        public void StartMirroring()
        {
            try
            {
                Thread.Sleep(200);
                if (_mirroredForm == null)
                {
                    CreateMirrorForm();
                }

                _clicked = true;

                uint   processID;
                IntPtr foregroundWnd = User32.GetForegroundWindow();
                User32.GetWindowThreadProcessId(foregroundWnd, out processID);
                Process prc = Process.GetProcessById((int)processID);

                _mirrorState.SelectedProcess = prc;

                if (_defaultScreenshotWindows.Contains(_mirrorState.SelectedProcess.ProcessName))
                {
                    _mirrorState.MirrorType = MirrorState.MirrorTypes.Screenshot;
                    User32.ShowWindow(_mirrorState.SelectedProcess.MainWindowHandle, User32.SW_SHOWMAXIMIZED);
                }
                else
                {
                    _mirrorState.MirrorType = MirrorState.MirrorTypes.Window;
                }
                if (InvokeRequired)
                {
                    Invoke((Action)(() =>
                    {
                        WindowState = FormWindowState.Minimized;
                        Thread.Sleep(250);

                        DrawImageToForm();

                        timer1.Start();
                        _mirroredForm.Show();

                        _mirrorState.Active = true;
                        _itemStop.Enabled = true;

                        notifyIcon1.Icon = Properties.Resources.icon_active;
                    }));
                }
                else
                {
                    this.WindowState = FormWindowState.Minimized;
                    Thread.Sleep(250);

                    DrawImageToForm();

                    timer1.Start();
                    _mirroredForm.Show();

                    _mirrorState.Active = true;
                    _itemStop.Enabled   = true;

                    notifyIcon1.Icon = Properties.Resources.icon_active;
                }

                GC.Collect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Application.Exit();
            }
        }
Ejemplo n.º 2
0
 private void OriginalForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     User32.UnregisterHotKey(this.Handle, 1);
 }
Ejemplo 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);
            }
        }