用另一个 Winform HWND 替换现有的 Winform HWND?

发布于 2024-08-22 05:58:40 字数 100 浏览 3 评论 0原文

我正在尝试劫持现有窗口并将其替换为我拥有的 Winforms 的内容。 我认为将表单的内部句柄与我想要覆盖的句柄交换会非常酷,并且想知道是否有人尝试过?

干杯, 弗洛里安

I'm trying to hijack an existing window and replace it with the contents of a Winforms I own.
I figured it would be pretty cool swapping the form's inner handle with the one I want to override, and wondered if anyone ever tried it?

Cheers,
Florian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谜泪 2024-08-29 05:58:40

如果您正在要替换的窗口的进程和线程中执行,这应该很容易尝试。如果您没有在原始窗口的进程和线程上运行,那么它工作的可能性就小得多。如果这是您尝试替换的 Windows shell 的一部分,那么您不太可能让它工作。

如果您可以进行窗口替换,则必须以父窗口期望原始子窗口响应的方式响应父窗口,但想必您已经考虑过这一点。

如果父窗口持有原始子窗口的窗口句柄,那么您尝试替换它就会失败(它仍然会尝试与原始句柄对话)。但如果它通过 id 跟踪子项,那么您所要做的就是为您的窗口指定相同的窗口 id,并使用 SetWindowPos 为其指定与原始子项相同的大小、位置和 z 顺序,然后销毁该窗口原来的孩子。

我祝你好运,这是高风险行为,但是你可以尝试的所有其他技巧(例如子类化和挂钩)也是如此。

This should easy to try if you are executing in the process and thread of the window you want to replace. If you aren't running on the process and thread of the original window then it's much less likely to work. If this is a part of the Windows shell that you are trying to replace, then it's very unlikely that you will get this to work.

If you can do the window replacement, you will have to respond the the parent window in the way that it expects the original child window to respond, but presumably you have already thought about that.

If the parent window is holding the window handle of the original child, then your attempt to replace it will just fail (it will still try and talk to the original handle). but if it's keeping track of the child by id, then all you have to do is give your window the same window id, and use SetWindowPos to give it the same size and location and z-order as the original child, and then destroy the original child.

I wish you luck, this is high risk behavior, but so are all of the other hacks that you could try instead like subclassing and hooking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文