/// <summary> /// Panel resize handles the host panel resizing in FrameTrapped. /// </summary> /// <param name="sender"> /// </param> /// <param name="e"> /// </param> private void PanelResize(object sender, EventArgs e) { NativeModel.SetWindowPos( _gameProcessMainWindowHandle, Process.GetCurrentProcess().MainWindowHandle, 0, 0, _panel.Width, _panel.Height, NativeModel.SWP_NOZORDER | NativeModel.SWP_NOACTIVATE); }
/// <summary> /// Creates child process. /// </summary> /// <param name="panelHandle">The panel handle.</param> private void CreateGameProcess(IntPtr panelHandle) { IsLoading = true; Task.Factory.StartNew( () => { // Get all instances of SSFIV.exe running on the local // computer. Process[] sfivInstances = Process.GetProcessesByName("SSFIV"); if (sfivInstances.Length > 0) { sfivInstances[0].Kill(); } _gameProcess = new Process { StartInfo = { FileName = _gameExecuteablePath, WindowStyle = ProcessWindowStyle.Minimized, RedirectStandardInput = true, ErrorDialog = false, UseShellExecute = false, } }; _gameProcess.EnableRaisingEvents = true; _gameProcess.Exited += GameProcessExited; lock (this) { uint _oldErrorMode = NativeModel.SetErrorMode(NativeModel.SEM_FAILCRITICALERRORS | NativeModel.SEM_NOGPFAULTERRORBOX); try { _gameProcess.Start(); } catch (InvalidOperationException invEx) { // Expected, handled Debug.WriteLine(invEx.Message); } catch (Exception ex) { Execute.OnUIThread(() => System.Windows.MessageBox.Show( System.Windows.Application.Current.MainWindow, string.Format("The game coulnd't start: {0} !", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error)); } _gameProcess.WaitForInputIdle(); // For correct responding, it's important to let sleep our thread for a while. System.Threading.Thread.Sleep(1000); while (_gameProcessMainWindowHandle == IntPtr.Zero) { Thread.Sleep(100); _gameProcessMainWindowHandle = _gameProcess.MainWindowHandle; _gameProcess.Refresh(); } int dwStyle = NativeModel.GetWindowLong(_gameProcessMainWindowHandle, NativeModel.GWL_STYLE); NativeModel.SetWindowLong(_gameProcessMainWindowHandle, NativeModel.GWL_STYLE, new IntPtr(dwStyle & ~NativeModel.WS_CAPTION & ~NativeModel.WS_THICKFRAME)); NativeModel.SetWindowPos(_gameProcessMainWindowHandle, IntPtr.Zero, 0, 0, Convert.ToInt32(Math.Floor((double)_panel.Width)), Convert.ToInt32(Math.Floor((double)_panel.Height)), NativeModel.SWP_ASYNCWINDOWPOS); _panel.Invoke(new MethodInvoker(delegate { NativeModel.SetParent(_gameProcessMainWindowHandle, _panel.Handle); })); } Execute.OnUIThread(() => { NotifyOfPropertyChange(() => IsStopped); EnableWindow(); }); PanelResize(this, null); }).ContinueWith( (t) => { Execute.OnUIThread(() => { IsLoading = false; }); } ); }