前景窗口与活动窗口

发布于 2024-09-28 02:25:07 字数 210 浏览 7 评论 0原文

在Windows中,前台窗口和活动窗口有什么区别?具体来说,什么情况下前台窗口不能是活动窗口?如果这两个术语指的是同一概念,那么为什么有两个术语。

msdn 文档此处提到“单击窗口,或使用 ALT+TABALT+ESC 键组合”使窗口和前景窗口都处于活动状态。这两个术语之间没有明确的区别。检查

In Windows, what is the difference between foreground and active window? To be specific, under what circumstances can a foreground window not be an active window? If the 2 terms are referring to the same concept why there're 2 terms.

The msdn documentation here mentions "clicking a window, or by using the ALT+TAB or ALT+ESC key combination" makes a window active as well as foreground. There is nothing explicitly about the difference between the 2 terms.Check MSDN.

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

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

发布评论

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

评论(2

莫多说 2024-10-05 02:25:07

活动窗口(GetActiveWindow() 的结果)是附加到获取输入的调用线程的窗口。前台窗口(GetForegroundWindow() 的结果)是当前正在获取输入的窗口,无论其与调用线程的关系如何。活动窗口本质上是针对您的应用程序进行本地化的;前台窗口对于系统来说是全局的。

例如,如果属于另一个进程的窗口是前台,则从您自己的进程中调用 GetActiveWindow() 将返回 NULL

我相信,作为前景窗口意味着作为活动窗口,但反之则不然。另请注意,在现代 Windows 中,应用程序通常无法使用 SetForegroundWindow() 从另一个进程窃取焦点(除非该进程已通过 AllowSetForegroundWindow 显式授予权限)。

The active window (the result of GetActiveWindow()) is the window attached to the calling thread that gets input. The foreground window (the result of of GetForegroundWindow()) is the window that's currently getting input regardless of its relationship to the calling thread. The active window is essentially localized to your application; the foreground window is global to the system.

For example, if a window belonging to another process is the foreground, calling GetActiveWindow() from within your own process will return NULL.

I believe that it's true that being the foreground window implies being the active window, but the converse is not true. Also note that in modern Windows, applications generally cannot use SetForegroundWindow() to steal focus from another process (unless that process has explicitly given permission via AllowSetForegroundWindow).

清风疏影 2024-10-05 02:25:07

我发现 MSDN 中的描述也有点令人困惑,但这是我的修改意见:

首先,前景和背景窗口与活动窗口无关,它与线程有关,请参见下文。因此,从技术上讲,将背景窗口作为活动窗口是可行的,但是这很令人困惑,并且系统不会为您执行此操作,而是您的应用程序需要调用例如 SetWindowPos 来使背景窗口处于活动状态。

系统一次只能有一个活动的顶级窗口,如果您正在处理子窗口,系统将激活顶级窗口。然后,所有输入都会定向到活动窗口,然后通常传递到子窗口。

/----------------------\
|                      |
|   FOREGROUND WINDOW  |--\
|                      |  |
\----------------------/  |
  | BACKGROUND WINDOW     |
  \-----------------------/

/----------------------\
|                      |
|    ACTIVE WINDOW     |--\
|                      |  |
\----------------------/  |
  | BACKGROUND WINDOW     |
  \-----------------------/

来自 MSDN

活动窗口

活动窗口是用户当前正在使用的应用程序的顶级窗口。为了让用户轻松识别活动窗口,系统将其放置在 z 顺序的顶部,并将其标题栏和边框的颜色更改为系统定义的活动窗口颜色。只有顶层窗口才能是活动窗口。当用户使用子窗口时,系统激活与子窗口关联的顶级父窗口。

前台/后台

每个进程可以有多个执行线程,每个线程都可以创建窗口。创建用户当前正在使用的窗口的线程称为前台线程,该窗口称为前台窗口。所有其他线程都是后台线程,后台线程创建的窗口称为后台窗口。

I find the description in MSDN a bit confusing as well but here is my revised take:

First a foreground and background window have nothing to do with active windows, it has to do with threading, see below. So it is technically possible to have background window as an active window however it is confusing and the system doesn't do this for you, instead your app needs to call e.g. SetWindowPos to make the background window active.

The system can only have one active top-level window at a time, the system will activate the top-level window if you are working on a child window. All input is then directed to the active window and then normally passed to the child window.

/----------------------\
|                      |
|   FOREGROUND WINDOW  |--\
|                      |  |
\----------------------/  |
  | BACKGROUND WINDOW     |
  \-----------------------/

/----------------------\
|                      |
|    ACTIVE WINDOW     |--\
|                      |  |
\----------------------/  |
  | BACKGROUND WINDOW     |
  \-----------------------/

From MSDN

Active Window

An active window is the top-level window of the application with which the user is currently working. To allow the user to easily identify the active window, the system places it at the top of the z-order and changes the color of its title bar and border to the system-defined active window colors. Only a top-level window can be an active window. When the user is working with a child window, the system activates the top-level parent window associated with the child window.

Foreground/Background

Each process can have multiple threads of execution, and each thread can create windows. The thread that created the window with which the user is currently working is called the foreground thread, and the window is called the foreground window. All other threads are background threads, and the windows created by background threads are called background windows.

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