WPF opening up exe program within WPF window
Not sure if this is possible but is there a way to open up ano开发者_StackOverflowther program like notepad within the container of a WPF window? similiar to that of being able to open a web page using the webbrowser control?
Basically I would like to open notepad or other exe but keep it constrained within the WPF window container using xaml/c# code? not sure if possible?
Yes it is possible.
All you have to do is:
- Create a WindowsFormsHost and add it to a panel in your UI
- Start the process (such as Notepad) using Process.Start
- Call process.WaitForInputIdle
- Use process.MainWindowHandle to get the window handle
- Call SetWindowPos to set the process's window to the coordinates and Z Order of the HwndHost window
- Hook both the HwndHost and the process.MainWindowHandle to detect size changes and repeat step 5.
It is quite straightforward to do all of this. The effect is the entire Notepad window (or whatever application you started) appears and behaves exactly as if it were part of your WPF application.
managed to do this using the SetParent method
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwc, IntPtr hwp);
so by getting the handles for wpf window and then the exe window, I was able to set the wpf window as parent so it gave a simulation of being embedded (also closed the title bar etc)
got help from here: http://channel9.msdn.com/forums/TechOff/250417-Hide-window-caption-in-c/
You can't do that.
The reason you can view a web page is because IE was designed using an architecture that allows it - the rendering engine isn't actually part of the actual IE executable, but a DLL which exposes a component.
Generic EXEs do not work that way, and you cannot embed them inside your app.
精彩评论