我想在我的WPF应用程序中托管外部进程的窗口。我这样得Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",sender, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(content)); //content: HTML format
context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
:
HwndHost
并像这样使用它:
class HwndHostEx : HwndHost
{
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
private IntPtr ChildHandle = IntPtr.Zero;
public HwndHostEx(IntPtr handle)
{
this.ChildHandle = handle;
}
protected override System.Runtime.InteropServices.HandleRef BuildWindowCore(System.Runtime.InteropServices.HandleRef hwndParent)
{
HandleRef href = new HandleRef();
if (ChildHandle != IntPtr.Zero)
{
SetParent(this.ChildHandle, hwndParent.Handle);
href = new HandleRef(this, this.ChildHandle);
}
return href;
}
protected override void DestroyWindowCore(System.Runtime.InteropServices.HandleRef hwnd)
{
}
}
其中 HwndHostEx host = new HwndHostEx(handle);
this.PART_Host.Child = host;
是外部窗口的句柄我想主持,handle
是我的WPF窗口内的边框:
PART_Host
这给了我一个例外:
<StackPanel UseLayoutRounding="True"
SnapsToDevicePixels="True"
Background="Transparent">
<Border Name="PART_Host" />
...
很抱歉我缺乏知识,但在WPF应用程序中托管外部窗口的正确方法是什么?
答案 0 :(得分:3)
在致电&#39; SetParent&#39;之前这样做:
public const int GWL_STYLE = (-16);
public const int WS_CHILD = 0x40000000;
SetWindowLong(this.ChildHandle, GWL_STYLE, WS_CHILD);
答案 1 :(得分:1)
查看docs:
似乎无法从WPF应用程序中的另一个进程“附加”已经运行的Window。
如何获得传递给HwndHostEx构造函数的句柄?