2013-12-08 49 views
0

我有這個代碼,現在讓我打開notepad.exe在WPF窗口內,問題是當我打開窗口,我看到記事本,但沒有在窗口內的完整大小,希望有人能幫助,謝謝:最大尺寸在wpf窗口中打開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... 
    } 
    } 
} 
+0

你檢查出窗口樣式使記事本無國界(如果你願意),還試圖設置記事本的主窗口的狀態最大化? – Warty

+0

我該如何設置windows狀態?以及如何檢查Windows風格,看到記事本無國界? – eran10

+0

請問以下網站可以幫助你嗎... http://stackoverflow.com/questions/4743213/application-that-c​​an-open-program-in-full-screen或http://stackoverflow.com/questions/14799691/ wpf-maximizing-borderless-window-by-taking-in-account-the-user-taskbar – bucketblast

回答

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); 
+0

-1:OP已經有記事本開始。 –

+0

@Jhon Saunders他使用c#並添加了「user32.dll」。我建議他使用System.Diagnostic,這讓他具備了C#的能力,而且我不理解記事本已經開始。在給出命令之前它如何開始? –

+1

請閱讀原始問題。 OP能夠啓動記事本。 OP需要幫助調整大小。 –