我正在开发一个需要主机 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/