【问题标题】:open exe inside wpf window in maximum size在 wpf 窗口中以最大大小打开 exe
【发布时间】: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,虽然它太长了,我记不住了。

标签: c# wpf exe


【解决方案1】:

使用 System.Diagnostics

ProcessStartInfo strtInf = new ProcessStartInfo("notepad.exe");
strtInf.WindowStyle = ProcessWindowStyle.Maximized;
Process.Start(strtInf);

如果你想打开文件

你在后面加上这个

strtInf.Arguments = "E:\\Tableaux\\atelier.sql";
Process.Start(strtInf);

【讨论】:

  • @Jhon Saunders 他正在使用 c# 并添加了“user32.dll”。我建议他使用 System.Diagnostic 这给了他 c# 的能力,我不明白记事本已经开始了。怎么能在下达命令之前启动??
  • 请阅读原始问题。 OP 能够启动记事本。 OP 在调整大小方面需要帮助。
  • 我需要帮助,当我打开窗口时告诉我的新表单中的笔记最大化,空的记事本很好,只是如何告诉它最大化
猜你喜欢
  • 1970-01-01
  • 2011-06-11
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多