WPF控件中的本机Win32窗口

时间:2021-04-21 00:07:21

I am developing an application that needs to a host native Win32 window and somehow i have no clues how to do that.

我正在开发一个需要主机本地Win32窗口的应用程序,但是不知何故,我没有任何线索可以说明这一点。

I need to create a WPF dialog window that could display native Win32 control on it. This dialog window will have WPF controls on it as well, so i am looking for some sort of Grid that i could take HWND of and send it to the unmanaged C++ control, so it could draw on it. Is that possible ?

我需要创建一个WPF对话框窗口,可以在窗口上显示本机Win32控件。这个对话框窗口也会有WPF控件,所以我正在寻找某种网格,我可以将HWND发送给unmanaged c++控件,这样它就可以在上面绘制了。这有可能吗?

I don't need to know what happens within that surface, just need to let C++ dll to draw on it and all i need to do is to pass HWND that has proper size (which i know).

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

I am kinda new to WPF (used to do win32 programming) and quite lost (but i now how to interface it to C# .NET etc)

我对WPF有点陌生(以前做win32编程),也很迷茫(但是现在我知道如何与c#。net接口)

Would be great if you could send me any hints :)

如果你能给我一些提示就太好了。

1 个解决方案

#1


12  

you can start by following the instructions/steps here: Hosting Win32 Content in WPF

您可以从以下指导/步骤开始:在WPF中托管Win32内容

from the article introduction:

从文章简介:

A Walkthrough of Win32 Inside Windows Presentation Framework (HwndHost)

Windows Presentation Framework (HwndHost)中的Win32演练

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.

要在WPF应用程序中重用Win32内容,请使用HwndHost,它是一个使HWNDs看起来像WPF内容的控件。与HwndSource一样,HwndHost很容易使用:从HwndHost派生并实现BuildWindowCore和驱逐舰windowcore方法,然后实例化HwndHost派生类并将其放在WPF应用程序中。

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

如果Win32逻辑已经打包为控件,那么BuildWindowCore实现仅仅是对CreateWindow的调用。

then if you have a specific issue ask here in SO and people will help you on specific points.

如果你有什么特别的问题,可以在这里问,人们会在一些特定的问题上帮助你。

#1


12  

you can start by following the instructions/steps here: Hosting Win32 Content in WPF

您可以从以下指导/步骤开始:在WPF中托管Win32内容

from the article introduction:

从文章简介:

A Walkthrough of Win32 Inside Windows Presentation Framework (HwndHost)

Windows Presentation Framework (HwndHost)中的Win32演练

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.

要在WPF应用程序中重用Win32内容,请使用HwndHost,它是一个使HWNDs看起来像WPF内容的控件。与HwndSource一样,HwndHost很容易使用:从HwndHost派生并实现BuildWindowCore和驱逐舰windowcore方法,然后实例化HwndHost派生类并将其放在WPF应用程序中。

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

如果Win32逻辑已经打包为控件,那么BuildWindowCore实现仅仅是对CreateWindow的调用。

then if you have a specific issue ask here in SO and people will help you on specific points.

如果你有什么特别的问题,可以在这里问,人们会在一些特定的问题上帮助你。