コード例 #1
0
        private Process GetProcessFromActiveWindow()
        {
            try
            {
                IntPtr foregroundWnd = User32.GetForegroundWindow();
                uint   prcId;
                User32.GetWindowThreadProcessId(foregroundWnd, out prcId);
                Process prc = Process.GetProcessById((int)prcId);

                return(prc);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(null);
            }
        }
コード例 #2
0
 private bool EnumWindowsProc(IntPtr hWnd, int lParam)
 {
     try
     {
         string strTitle = GetWindowText(hWnd);
         if (strTitle != "" & User32.IsWindowVisible(hWnd)) //
         {
             uint prcId;
             User32.GetWindowThreadProcessId(hWnd, out prcId);
             _openWindows.Add(Process.GetProcessById((int)prcId));
         }
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         return(false);
     }
 }
コード例 #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();
            }
        }