예제 #1
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);
     }
 }
예제 #2
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);
            }
        }