c# - WPF 控件中的 native Win32 窗口

标签 c# .net c++ wpf winapi

我正在开发一个需要主机 native Win32 窗口的应用程序,但不知何故我不知道如何做到这一点。

我需要创建一个可以在其上显示 native Win32 控件的 WPF 对话框窗口。这个对话框窗口也将有 WPF 控件,所以我正在寻找某种网格,我可以获取 HWND 并将其发送到非托管 C++ 控件,以便它可以在上面绘制。 这可能吗?

我不需要知道那个表面发生了什么,只需要让 C++ dll 在它上面绘制,我需要做的就是传递具有适当大小(我知道)的 HWND。

我对 WPF 有点陌生(以前用于 win32 编程)并且很迷茫(但我现在如何将它连接到 C# .NET 等)

如果你能给我任何提示就太好了:)

最佳答案

您可以按照此处的说明/步骤开始:Hosting Win32 Content in WPF

来自文章介绍:

Win32 Inside Windows Presentation Framework (HwndHost) 演练

To reuse Win32 content inside WPF applications, use HwndHost, which is a control that makes HWNDs look like WPF content. Like HwndSource, HwndHost is straightforward to use: derive from HwndHost and implement BuildWindowCore and DestroyWindowCore methods, then instantiate your HwndHost derived class and place it inside your WPF application.

If your Win32 logic is already packaged as a control, then your BuildWindowCore implementation is little more than a call to CreateWindow.

然后,如果您有具体问题,请在 SO 中提问,人们会在具体问题上帮助您。

关于c# - WPF 控件中的 native Win32 窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7493082/

相关文章:

c# - svcutil.exe 或测试 wcf 服务 JSON 输出?

.net - DBML 定制与再生

c# - 获取所有业务部门

c# - SSIS - PipelineComponent 中的 ProcessInput 被多次调用

c# - 俄罗斯方 block 清晰的线条问题

c# - 确定服务器是否正在监听给定端口

c++ - 如何正确声明这个 vector ?

c++ - 指向抽象基类的指针需要一些转换吗? C++

c++ - Boost线程 - 超出范围的可能性

c# - 如何在 blazor 组件中显示来自后端的自定义引导警报