Windows 中的 GetDesktopWindow 和 OpenInputDesktop API 之间有什么区别? [英] What is the difference between the GetDesktopWindow and OpenInputDesktop APIs in Windows?

查看:24
本文介绍了Windows 中的 GetDesktopWindow 和 OpenInputDesktop API 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GetDesktopWindowOpenInputDesktop API 在 Windows 中的使用区别是什么?

What is the usage difference between the GetDesktopWindow and OpenInputDesktop APIs in Windows?

推荐答案

至于他们做什么:

GetDesktopWindow() 返回调用线程当前关联的任何桌面的根"HWND;最好将其视为获取 root HWND".桌面上的所有其他 windows/HWND 不知何故都是这个的后代.顶级窗口是直接子窗口.(仅消息窗口是一种特殊情况,它们不显示在 HWND 树上,但仍属于桌面.)请注意,这与包含所有文件和图标的背景窗口不同在它上面,这可能正确地称为Shell 桌面"窗口,您可以使用 GetShellWindow() - 它恰好是一种特殊类型的顶级窗口.

GetDesktopWindow() returns the 'root' HWND of whichever desktop the calling thread is currently associated with; it's perhaps better thought of as "Get root HWND". All the other windows/HWNDs on the desktop are somehow descendants of this. Top-level windows are direct children. (Message-only windows are a special case, they don't show up on the HWND tree, but still belong to a desktop.) Note that this is not the same as the window that is at the background with all the files and icons on it, that's perhaps properly called the "Shell Desktop" window, and you can get that using GetShellWindow() - it just happens to be a special type of top-level window.

OpenInputDesktop() 返回当前处于活动状态并接收用户输入的任何桌面的 HDESK.每个桌面都有自己的 HWND 树,它们以根窗口或桌面"窗口为根.

OpenInputDesktop() returns the HDESK of whichever desktop currently is active and receiving user input. Each desktop has its own tree of HWNDs rooted at the root window, or 'desktop' window.

至于它们之间的关系,一旦有了HDESK,就可以使用SetThreadDesktop将该桌面设置为线程的默认桌面;然后调用 GetDesktopWindow 将返回该桌面的根 HWND.(请注意,您必须首先获得使用该 HDESK 的权限,例如,如果输入桌面是锁定的桌面,则通常情况并非如此.)您也可以使用 GetThreadDesktop()获取当前线程的 HDESK.

As to how these are related, once you have a HDESK, you can use SetThreadDesktop to set that desktop as the thread's default desktop; then calling GetDesktopWindow will return the root HWND for that desktop. (Note that you have to have permission to use that HDESK in the first place, which is usually not the case if the input desktop is the locked desktop, for example.) You can also use GetThreadDesktop() to get the HDESK for the current thread.

如果您想遍历应用程序所在桌面的 HWND 树,您可以使用 GetDesktopWindow() - Spy++ 类型的应用程序可能会使用它来获取根窗口并使用 GetWindow() 或类似方法从那里遍历.但是大多数应用程序都乐于保持自己的状态,因此不需要知道外面还有哪些其他窗口.也许一个常见的用途是检查任意窗口是否是顶级的:使用 GetAncestor(hwnd, GA_PARENT),并检查返回值是否匹配GetDesktopWindow().

You might use GetDesktopWindow() if you wanted to traverse the HWND tree for the desktop that your application is on - Spy++-type apps might use this to get the root window and traverse from there using GetWindow() or similar, perhaps. But most apps are happy keeping to themselves so don't need to be aware of what other windows are out there. Perhaps one common use is for checking if an arbitrary window is top-level: use GetAncestor(hwnd, GA_PARENT), and check if the return value matches GetDesktopWindow().

OpenInputDesktop() 可能更不常用;大多数应用程序只是坐在它们启动的桌面上并停留在那里.也许如果您编写了一个桌面切换实用程序来创建用户可以在其中切换的多个桌面,那么该应用程序或其他一些应用程序可以使用它来确保它在当前的桌面上显示,然后再在那里显示 UI,但这确实不是一个常见的场景根本.在某个阶段可能可以编写诸如放大镜或屏幕阅读器或其他带有 UI 的应用程序,它们希望在用户切换桌面时跟随用户",但这不适用于安全的锁定桌面 -所以这些类型的应用程序必须使用另一种方式来处理这种情况.

OpenInputDesktop() is perhaps even more rarely used; most apps just sit on the desktop they are started on and stay there. Perhaps if you wrote a desktop switching utility that created multiple desktops that the user could switch between, then that app or some other app could use this to make sure it was on the current one before displaying UI there, but that's really not a common scenario at all. It might have been possible at one stage to write something like a magnifier or screen reader or other app with UI that would want to "follow the user" as they switch desktops, but that doesn't work with the locked desktop which is secure - so these types of apps have to use another way to work with that case instead.

这篇关于Windows 中的 GetDesktopWindow 和 OpenInputDesktop API 之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆