简体   繁体   English

如何将本机窗口处理程序 (HWND) 嵌入到 C# WPF 应用程序中

[英]How to embed a native window handler (HWND) into a C# WPF app

I'm working on an application for making video calls using pjsip.我正在开发一个使用 pjsip 进行视频通话的应用程序。

I have:我有:

  1. The core library: A static library, which uses pjsua2, in C++.核心库:一个静态库,使用 pjsua2,在 C++ 中。
  2. A dynamic library for the C++/CLI bridge that wraps all the public interfaces from 1. C++/CLI 桥接器的动态库,它包装了 1.x 中的所有公共接口。
  3. A WPF app, that links against 2.一个 WPF 应用程序,链接到 2。

The WPF app can open the capture device. WPF 应用程序可以打开捕获设备。 Pjsip creates a sdl window for the video preview, and returns its HWND as a void* in the C++ side. Pjsip 为视频预览创建了一个 sdl 窗口,并在 C++ 端将其 HWND 作为 void* 返回。

I am "casting" it into a std::string -- using std::stringstream stream operators -- and marshalling it to the WPF side.我将它“投射”到 std::string 中——使用 std::stringstream 流运算符——并将其编组到 WPF 端。

I'd like to embed that window into my WPF main window.我想将该窗口嵌入到我的 WPF 主窗口中。 Is that possible?那可能吗?

You can use Hwnd​Host class and host native windows in WPF.您可以在 WPF 中使用Hwnd​Host类并托管本机窗口。

Hwnd​Host is part of System.Windows.Interop WPF namespace. Hwnd​HostSystem.Windows.Interop WPF 命名空间的一部分。

Here is Microsoft example, but it is little tedious.这是微软的例子,但它有点乏味。

https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-win32-control-in-wpf https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-win32-control-in-wpf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM