Windows管理的2个窗口是否可以具有相同的窗口句柄值?

发布于 2024-12-03 01:05:39 字数 87 浏览 0 评论 0原文

Windows管理的2个窗口是否可以具有相同的窗口句柄值?

考虑这 2 个窗口由同一进程打开以及这 2 个窗口由 2 个不同进程打开这两种情况。

Is it possible for 2 windows managed by Windows to have the same window handle value?

Consider both cases when these 2 windows are opened by the same process and when these 2 windows are opened by 2 different processes.

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

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

发布评论

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

评论(2

|煩躁 2024-12-10 01:05:39

快速回答:不,如果它们位于同一个桌面内,这是不可能的,窗口管理器发出的每个窗口句柄在窗口的所有存在中都是唯一的(在其桌面内),否则它无法唯一标识该窗口system当前window station桌面(MSDN将其定义为“逻辑显示表面”,“包含用户界面对象,例如窗口、菜单和挂钩;它可以是用于创建和管理窗口”)。


长答案:

讨论了该问题 这里,它指向本文。看来 HWND 是桌面本地的,因此您可以有两个相同的 HWND 指向两个不同的窗口,但它们必然是在两个独立的桌面,因此没有歧义(您传递给每个 user32 函数的 WM 句柄隐式引用当前桌面,要转到另一个桌面,您必须使用 SetThreadDesktop , 和如果您的线程在当前桌面中拥有任何桌面包含的对象,则此调用将失败)。

另一方面,当一个窗口被销毁时,它的句柄可以被重用,但是 IIRC 窗口管理器采用了一些技术来避免立即重用句柄。

Quick answer: no, it's not possible if they are inside the same desktop, every window handle issued by the window manager is unique (inside its desktop) throughout all the existence of the window, otherwise it couldn't uniquely identify such window on the system current window station desktop (which is defined by MSDN as "a logical display surface" that "contains user interface objects such as windows, menus, and hooks; it can be used to create and manage windows").


Long answer:

The issue is discussed here, which points to this article. It seems that HWNDs are local to desktops , so you can have two identical HWNDs that point to two different windows, but they are necessarily in two separated desktops, so there's no ambiguity (the WM handle you pass to every user32 function refers implicitly to the current desktop, to go to another one you have to use SetThreadDesktop, and this call fails if your thread owns any desktop-contained object into the current desktop).

On the other hand, when a window is destroyed, its handle can be reused, but IIRC the window manager employs some techniques to avoid immediately reusing a handle.

晚雾 2024-12-10 01:05:39

每个在特定时间打开的窗口都会有一个唯一的句柄。
但是,一旦窗口关闭,它们就可以重复使用。

Every window open at a particular time will have a unique handle.
However, they can be reused once a window is closed.

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