Exemplo n.º 1
0
        private void Window_DrawGraphics(object sender, DrawGraphicsEventArgs e)
        {
            ProcessWindowHelper.GetWindowThreadProcessId(ProcessWindowHelper.GetForegroundWindow(), out int activeProcId);

            float xIndex = 10, yIndex = 10;

            if (activeProcId == _process.Id)
            {
                if (!_primeParts.Any())
                {
                    e.Graphics.DrawTextWithBackground(_font, _whiteBrush, _grayBrush, xIndex, yIndex, "No parts found");
                }

                foreach (PrimePart primePart in _primeParts)
                {
                    e.Graphics.DrawTextWithBackground(_font, _whiteBrush, _grayBrush, xIndex, yIndex, primePart.ToString());

                    yIndex += _font.FontSize + 5;
                }
            }
            else
            {
                e.Graphics.ClearScene();
            }
        }
Exemplo n.º 2
0
        public void HideMenubar()
        {
            var mainWindowHanle = Process.MainWindowHandle;
            var hMenu           = ProcessWindowHelper.HideMenubar(mainWindowHanle);

            if (hMenu != IntPtr.Zero)
            {
                Process.StartInfo.EnvironmentVariables["MenuBarHandle"] = hMenu.ToString();
            }
        }
Exemplo n.º 3
0
 private void HandleDockedProcess()
 {
     if (!AutoKillHostedProcess)
     {
         if (dockedWindowThread != 0 && parentWindowThread != 0)
         {
             AttachThreadInput(dockedWindowThread, parentWindowThread, false);
         }
         ProcessWindowHelper.RecoverCaptionBarAndBorder(Process, Process.MainWindowHandle);
         ShowMenubar();
         ProcessWindowHelper.SetParent(Process.MainWindowHandle, IntPtr.Zero);
     }
 }
Exemplo n.º 4
0
        public void ShowMenubar()
        {
            var strMenuHandle = Process.StartInfo.EnvironmentVariables["MenuBarHandle"];

            if (string.IsNullOrEmpty(strMenuHandle))
            {
                return;
            }
            int menu;

            if (int.TryParse(strMenuHandle, out menu))
            {
                OnBeforeShowMenubar();
                ProcessWindowHelper.ShowMenubar(Process.MainWindowHandle, (IntPtr)menu);
                OnAfterShowMenubar();
            }
        }
Exemplo n.º 5
0
        virtual protected void HostMainWindow()
        {
            if (_iscreated)
            {
                return;
            }
            _iscreated = true;
            if (Process == null)
            {
                throw new Exception("Please set the Process property of this HostedProcessWindow object!");
            }
            Process.Refresh();
            if (Process.MainWindowHandle == IntPtr.Zero)
            {
                Thread.Sleep(20);
                Process.Refresh();
            }
            if (Process.MainWindowHandle == IntPtr.Zero)
            {
                throw new Exception("Could not find the Process main window!");
            }
            ProcessWindowHelper.customerizeWindow(Process, Process.MainWindowHandle, true, true, true);
            var panel = new Panel();

            AddChildStyle();
            ProcessWindowHelper.SetParent(Process.MainWindowHandle, panel.Handle);
            var windowsFormsHost = new ProcessWindowHost {
                Child = panel, ProcessWindow = this
            };

            Content = windowsFormsHost;
            SizeChangedFunction(this);
            ProcessWindowHelper.ShowWindow(Process.MainWindowHandle);
            StartListeningForWindowChanges();
            Application.Current.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
            AppDomain.CurrentDomain.UnhandledException       += new UnhandledExceptionEventHandler(OnUnhandledException);
            uint dockedProcess;

            dockedWindowThread = GetWindowThreadProcessId(Process.MainWindowHandle, out dockedProcess);
            parentWindowThread = GetCurrentThreadId();
            AttachThreadInput(dockedWindowThread, parentWindowThread, true);
            if (WindowHosted != null)
            {
                WindowHosted(this);
            }
        }
Exemplo n.º 6
0
        virtual protected void SizeChangedFunction(Control control)
        {
            if (!_iscreated || Math.Abs(ActualWidth) <= 1 || Math.Abs(ActualHeight) <= 1)
            {
                return;
            }
            if (Process.MainWindowHandle != IntPtr.Zero)
            {
                //http://stackoverflow.com/questions/3286175/how-do-i-convert-a-wpf-size-to-physical-pixels/3286419#3286419
                var pixelWidth =
                    (int)(ActualWidth * Screen.PrimaryScreen.WorkingArea.Width / SystemParameters.WorkArea.Width);
                var pixelHeight =
                    (int)(ActualHeight * Screen.PrimaryScreen.WorkingArea.Height / SystemParameters.WorkArea.Height);
                //exclue the unnecessary rearrangement
                if (pixelWidth <= (int)this.MinWidth)
                {
                    pixelWidth = (int)this.MinWidth;
                }
                if (pixelHeight <= (int)this.MinHeight)
                {
                    pixelHeight = (int)this.MinHeight;
                }
                ProcessWindowHelper.MoveWindow(Process.MainWindowHandle, 0, 0, pixelWidth, pixelHeight, true);
                //the below line is needed, if some control in hosted window using OnResize to do layout, in this case the last line is used to trigger the control's layout, the next line won't trigger, it just move the window to change its position.
                ProcessWindowHelper.MoveWindow(Process.MainWindowHandle, 0, 0, pixelWidth, pixelHeight, true);

                //var win = Window.GetWindow(control);
                //if (win != null)
                //{
                //    var handle = new WindowInteropHelper(win).Handle;
                //    HwndSource source = (HwndSource)HwndSource.FromVisual(this);
                //    IntPtr hWnd = source.Handle;
                //    //MoveWindow(handle, 0, 0, pixelWidth, pixelHeight, true);
                //}

                //old code:
                //var win = Window.GetWindow(control); // System.Windows.Application.Current.MainWindow
                //if (win != null && win.IsAncestorOf(this))
                //{
                //    var point = this.TransformToAncestor(win).Transform(new Point(this.Left, this.Top));
                //    MoveWindow(Process.MainWindowHandle, point.X, point.Y, pixelWidth, pixelHeight, true);
                //}
            }
            InvalidateVisual();
        }
Exemplo n.º 7
0
 public void Hide()
 {
     ProcessWindowHelper.HideWindow(Process.MainWindowHandle);
 }
Exemplo n.º 8
0
 public void Show()
 {
     ProcessWindowHelper.ShowWindow(Process.MainWindowHandle);
 }
Exemplo n.º 9
0
 public void RemoveChildStyle()
 {
     ProcessWindowHelper.RemoveChildStyle(Process.MainWindowHandle);
 }
Exemplo n.º 10
0
 public void AddChildStyle()
 {
     ProcessWindowHelper.AddChildStyle(Process.MainWindowHandle);
 }