【发布时间】:2013-12-08 21:26:06
【问题描述】:
我有这段代码,现在让我在 wpf 窗口中打开 notepad.exe,问题是当我打开窗口时,我看到了记事本,但在窗口内没有全尺寸,希望有人能提供帮助,谢谢:
/// <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...
}
}
}
【问题讨论】:
-
您是否检查过窗口样式以使记事本无边框(如果您愿意),并尝试将记事本的主窗口状态设置为最大化?
-
我如何为它设置窗口状态?以及如何检查 windows 样式以查看记事本无边框?
-
参见 GetWindowLong 和 SetWindowLong(您必须 p/invoke)。至于调整内部窗口的大小,您可能必须在 Form 的调整大小事件中执行此操作 - 我想说的是 WinAPI 本身并不支持 Dock = Fill,虽然它太长了,我记不住了。