是否有可能抢夺和主机在一个孩子的WinForms窗口一个Win32 HWND控制?有可能、窗口、主机、孩子

2023-09-03 15:37:18 作者:少女心狙击手

我做了网上搜索,但他们谈论的是如何做到这一点的WPF。

I did a search online but they are talking about how to do this for WPF.

想象一下,一个Win32应用程序如下图所示,并假设应用程序本身允许创建新的Windows窗体窗口的子窗口。因此,他们可以互相交谈,我可以发送键presses,并控制父应用程序。

Imagine a win32 application like shown below, and assume the app itself allows creating new Windows Forms windows as child windows. So they can talk to each other, I can send keypresses, and control the parent application.

我想要做的是剥离在图像中概述了列表视图和主机它在我的WinForms窗口。因此,它的托管我的WinForms窗口中浮在上面,和移动控制,我的WinForms窗口移动。

What I want to do is to strip that listview outlined in the image and host it on my Winforms window. So it's hosted inside my Winforms window floating on top, and moves the control as my Winforms window moves.

我可以从父应用程序的.NET API中的HWND句柄,但我不知道我想要什么是可能的。如果是这样,怎么样?

I can get the hWnd handle from the parent app's .NET API but I am not sure if what I want is possible. If so, how?

推荐答案

如果您使用SetParent函数,那么它就像你期望的:

If you use the SetParent function, then it works just as you expect:

http://www.pinvoke.net/default.aspx/user32.setparent

您可能需要控制移动到合适的位置,在你的WinForms窗口,并有可能调整其大小也一样,使用的MoveWindow函数:

You might have to move the control to an appropriate location in your Winforms window and possibly resize it too, using the MoveWindow function:

http://www.pinvoke.net/default.aspx/user32.movewindow