SetParent(appWin, this.Handle);//this在这里是Panel控件4 // Remove border and whatnot 5 SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);7 // Move the window to overlay it on this window 8 MoveWindow(appWin, 0, 0, this.Width, this.Height, true); http://www.cnblogs.com/bitzhuwei/archive/2012/05/24/SmileWei_EmbeddedApp.html
SetParent要求控件的句柄(Handle),Grid没有这东西,只是布局用的 WPF里面的StackPanel、DockPanel这么好用的你从来没用过吧? 得到句柄 new System.Windows.Interop.WindowInteropHelper(窗口).Handle (PresentationSource.FromDependencyObject(控件) as System.Windows.Interop.HwndSource).Handle
没有思路。基本思路是,在你的wpf里定义一个窗口,再窗口上加载个panel之类的东西,要有Windows句柄才行的。
然后你使用process这个类打开外部程序(可以设置一些窗口的显示属性),获得外部程序的句柄后,利用SetParent,把外部程序句柄的父句柄设置为panel的句柄,这样外部exe程序就可以显示再panel上了,不过这个东西有些功能使用起来也很不如意的。不要在说你不知道句柄是什么之类的话。
SetParent(appWin, this.Handle);//this在这里是Panel控件4 // Remove border and whatnot
5 SetWindowLong(appWin, GWL_STYLE, WS_VISIBLE);7 // Move the window to overlay it on this window
8 MoveWindow(appWin, 0, 0, this.Width, this.Height, true);
http://www.cnblogs.com/bitzhuwei/archive/2012/05/24/SmileWei_EmbeddedApp.html
项目是wpf的 wpf没有panel控件。
在wpf里面如果用grid容器然后设置SetParent 加载的exe还是以主程序为父窗体。不是以grid。不清楚是怎么回事
WPF里面的StackPanel、DockPanel这么好用的你从来没用过吧?
得到句柄
new System.Windows.Interop.WindowInteropHelper(窗口).Handle
(PresentationSource.FromDependencyObject(控件) as System.Windows.Interop.HwndSource).Handle
IntPtr hwnd = ((HwndSource)PresentationSource.FromVisual(dockPanel1)).Handle;
Process app = System.Diagnostics.Process.Start("NOTEPAD.EXE");
IntPtr prsmwh = app.MainWindowHandle;
//设置父窗口
SetParent(prsmwh, hwnd);这样设置父窗体的话 出来的记事本是在整个窗体上 并不是在dock的。