我有这个代码,现在让我在wpf窗口内打开notepad.exe,问题是当我打开窗口时我看到记事本但窗口内没有全尺寸,希望有人可以帮忙,谢谢:< / p>
/// <summary>
/// Interaction logic for windows1.xaml
/// </summary>
public partial class windows1 : Window
{
public IntPtr MainWindowHandle { get; set; }
[DllImport("user32.dll", SetLastError = true)]
private static extern long SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
//[DllImport("user32.dll", SetLastError = true)]
//private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
public windows1()
{
InitializeComponent();
try
{
//External exe inside WPF Window
System.Windows.Forms.Panel _pnlSched = new System.Windows.Forms.Panel();
WindowsFormsHost windowsFormsHost1 = new WindowsFormsHost();
windowsFormsHost1.Child = _pnlSched;
this.gridtest.Children.Add(windowsFormsHost1);
ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Maximized;
Process PR = Process.Start(psi);
// true if the associated process has reached an idle state:
PR.WaitForInputIdle();
//System.Threading.Thread.Sleep(3000);
IntPtr hwd = PR.MainWindowHandle;
// loading exe to the wpf window:
SetParent(PR.MainWindowHandle, _pnlSched.Handle);
}
catch (Exception ex)
{
//Nothing...
}
}
}
答案 0 :(得分:0)
使用System.Diagnostics
ProcessStartInfo strtInf = new ProcessStartInfo("notepad.exe");
strtInf.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(strtInf);
如果您希望使用
打开文件您可以在
之后添加strtInf.Arguments = "E:\\Tableaux\\atelier.sql";
Process.Start(strtInf);