Exemplo n.º 1
0
        private void BringWindowToForeground(Process process)
        {
            try
            {
                var activeProcess   = GetProcessFromActiveWindow();
                var activeProcessID = activeProcess.Id;
                var selectedProcess = _mirrorState.SelectedProcess.Id;

                if (activeProcessID != selectedProcess && _mirrorState.MirrorType == MirrorState.MirrorTypes.Screenshot)
                {
                    //// Simulate a key press
                    //User32.keybd_event((byte)User32.ALT, 0x45, User32.EXTENDEDKEY | 0, 0);

                    //// Simulate a key release
                    //User32.keybd_event((byte)User32.ALT, 0x45, User32.EXTENDEDKEY | User32.KEYUP, 0);

                    User32.SetForegroundWindow(_mirrorState.SelectedProcess.MainWindowHandle);
                }

                var placement = GetPlacement(process.MainWindowHandle);

                User32.ShowWindow(process.MainWindowHandle, User32.SW_SHOWMAXIMIZED);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                Application.Exit();
            }
        }
Exemplo 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 { }
        }
Exemplo n.º 3
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();
            }
        }