WPF 互操作 - HwndHost 不会自动销毁托管窗口

发布于 2024-10-22 10:54:54 字数 523 浏览 2 评论 0原文

我无法确保正确销毁托管窗口。

我有一个 HwndHost 派生类,正在 TabControl 中显示(尽管这可能不相关)。我试图在选项卡关闭时销毁托管内容(而不是在包含的窗口关闭时)。

我目前拥有 myControlHost.Dispose() 效果的代码,这确保了 HwndHost. DestroyWindowCore 立即被调用。问题是,DestroyWindowCore 实际上并没有销毁托管的 HWND 内容!

我本以为这足以确保底层 CWnd 派生的应用程序接收到 WM_CLOSE 或其他内容,但这似乎不会发生 - Spy++ 仅报告已注册的正在发送消息“HwndSubclass.DetachMessage”。

我读到您不应该在 DestroyWindowCore 中显式向托管窗口发送 WM_CLOSE,因为这应该自动发生。

手动删除 HwndHost 派生控件时,确保正确销毁托管窗口的正确方法是什么?

I am having trouble ensuring a hosted window is correctly destroyed.

I have a HwndHost-derived class that I am displaying in a TabControl (though that is probably irrelevant). I am trying to destroy the hosted content when the tab closes (not when the containing window closes.)

I currently have code to the effect of myControlHost.Dispose(), which ensures that HwndHost.DestroyWindowCore is called immediately. The problem is, DestroyWindowCore does not actually destroy the hosted HWND content!

I would have thought that this was enough to ensure that the underlying CWnd-derived application receives a WM_CLOSE or something, but this does not seem to happen - Spy++ reports only a registered message "HwndSubclass.DetachMessage" being sent.

I have read that you are not supposed to explicitly send your hosted window a WM_CLOSE in the DestroyWindowCore, as this is supposed to happen automatically.

What is the correct way to ensure a hosted window is correctly destroyed when manually removing a HwndHost-derived control?

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

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

发布评论

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

评论(1

好听的两个字的网名 2024-10-29 10:54:54

根据这个MSDN文档,他们在DestroyWindowCore中调用DestroyWindow():
http://msdn.microsoft.com/en-us/library/ms752055.aspx

DestroyWindow() 会将 WM_CLOSE 消息发布到消息队列中,因此实际上您不需要或不应该直接发送/发布 WM_CLOSE。

在我的应用程序中,实际上我在子 DLL 中调用 DestroyWindow(),该子 DLL 在 DestroyWindowCore 回调中从 C# 端调用。然后,一切工作正常。

According to this MSDN document, they are calling DestroyWindow() in DestroyWindowCore:
http://msdn.microsoft.com/en-us/library/ms752055.aspx

DestroyWindow() will post WM_CLOSE message into message queue, so actually you don't need or should not directly send/post WM_CLOSE.

In my application, actually I am calling DestroyWindow() in a sub DLL which is called from C# side in DestroyWindowCore callback. Then, everything is working fine.

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