0

i have this code which for now let me open notepad.exe inside a wpf window, the problem is when i open the window i see the notepad but not in full size inside the window, hope someone can help, thanks :

/// <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...
    }
  }
}
Kjartan
  • 18,591
  • 15
  • 71
  • 96
spinker
  • 298
  • 4
  • 20
  • Have you checked out Window Style to make notepad borderless (if you wish), and also tried setting notepad's main window's state to maximized? – Warty Dec 08 '13 at 21:34
  • how do i set windows state for it ? and how to check for windows style to see notepad borderless? – spinker Dec 08 '13 at 21:43
  • Would the following sites help you...http://stackoverflow.com/questions/4743213/application-that-can-open-program-in-full-screen or http://stackoverflow.com/questions/14799691/wpf-maximizing-borderless-window-by-taking-in-account-the-user-taskbar – bucketblast Dec 08 '13 at 21:49
  • See GetWindowLong and SetWindowLong (you'll have to p/invoke). As for resizing the inner window, you might have to do that in your Form's resize events - I want to say that WinAPI doesn't natively support Dock = Fill, though it's been too long for me to remember. – Warty Dec 08 '13 at 21:50

1 Answers1

0

Using System.Diagnostics

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

If you want that the file open with

You add this just after

strtInf.Arguments = "E:\\Tableaux\\atelier.sql";
Process.Start(strtInf);
Kjartan
  • 18,591
  • 15
  • 71
  • 96
Ismail Gunes
  • 548
  • 1
  • 9
  • 24
  • @Jhon Saunders he is using c# and added "user32.dll". I advised him to use System.Diagnostic which gives him the ability of c# and I'dont understand notepad has already starting. How can it start before giving the command?? – Ismail Gunes Dec 08 '13 at 22:41
  • 1
    Please read the original question. OP is able to start Notepad. OP needs help with the resizing. – John Saunders Dec 08 '13 at 22:43
  • i need help by telling the note inside my new form to be maximized when i open the window, empty notepad is fine just how to tell it to be maximized – spinker Dec 09 '13 at 14:25