この手法は裏技?だと思うので、アプリごとに試行錯誤が必要になると思います。
APIの呼び出し順やパラメータがシビアで、ちょっとの違いでできたりできなかったりします。
xml
1<Window
2 x:Class="Questions243916.MainWindow"
3 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5 xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
6 Width="800"
7 Height="450">
8 <Grid>
9 <Grid.ColumnDefinitions>
10 <ColumnDefinition />
11 <ColumnDefinition Width="Auto" />
12 <ColumnDefinition />
13 </Grid.ColumnDefinitions>
14 <WindowsFormsHost>
15 <forms:Control x:Name="notepad" />
16 </WindowsFormsHost>
17 <GridSplitter
18 Grid.Column="1"
19 Width="8"
20 HorizontalAlignment="Stretch"
21 Background="DarkGray" />
22 <WindowsFormsHost Grid.Column="2">
23 <forms:Control x:Name="paint" />
24 </WindowsFormsHost>
25 </Grid>
26</Window>
cs
1using System;
2using System.Diagnostics;
3using System.Runtime.InteropServices;
4using System.Threading;
5using System.Windows;
6
7namespace Questions243916
8{
9 public partial class MainWindow : Window
10 {
11 [DllImport("user32")] private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
12 [DllImport("user32")] private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
13 [DllImport("user32")] private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
14 [DllImport("user32")] private static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, int bRepaint);
15
16 private const int GWL_STYLE = -16;
17 private const int WS_THICKFRAME = 0x00040000;
18 private const int WS_CAPTION = 0x00C00000;
19 private const int WS_CHILD = 0x40000000;
20
21
22 public MainWindow()
23 {
24 InitializeComponent();
25
26 {
27 var p = Process.Start(new ProcessStartInfo
28 {
29 FileName = "notepad",
30
31 // HiddenとしたいがMainWindowHandleが0になる
32 // FindWindowで探す必要あり 面倒なのでMinimized
33 //WindowStyle = ProcessWindowStyle.Hidden,
34 WindowStyle = ProcessWindowStyle.Minimized,
35 });
36 p.WaitForInputIdle();
37
38 var style = GetWindowLong(p.MainWindowHandle, GWL_STYLE);
39 style = style & ~WS_CAPTION & ~WS_THICKFRAME;
40 //style |= WS_CHILD; // メニュー有無
41 SetWindowLong(p.MainWindowHandle, GWL_STYLE, style);
42
43 SetParent(p.MainWindowHandle, notepad.Handle);
44
45 notepad.SizeChanged += (s, e)
46 => MoveWindow(p.MainWindowHandle, 0, 0, notepad.Width, notepad.Height, 1);
47 }
48
49 {
50 var p = Process.Start(new ProcessStartInfo
51 {
52 FileName = "mspaint",
53 WindowStyle = ProcessWindowStyle.Minimized,
54 });
55 p.WaitForInputIdle();
56 Thread.Sleep(500); // ウェイトがないと入らなかった
57
58 var style = GetWindowLong(p.MainWindowHandle, GWL_STYLE);
59 style = style & ~WS_CAPTION & ~WS_THICKFRAME;
60 SetWindowLong(p.MainWindowHandle, GWL_STYLE, style);
61
62 SetParent(p.MainWindowHandle, paint.Handle);
63
64 // なんかずれる それっぽくなったが根拠なし
65 var offset = (int)SystemParameters.MenuHeight
66 + (int)SystemParameters.ResizeFrameHorizontalBorderHeight * 2;
67 paint.SizeChanged += (s, e)
68 => MoveWindow(p.MainWindowHandle, 0, -offset, paint.Width, paint.Height + offset, 1);
69 }
70 }
71 }
72}
メモ帳とペイントを入れるだけでかなり苦労しました^^;
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。