Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreground Vs Active window

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.

like image 424
JavaMan Avatar asked Oct 15 '10 07:10

JavaMan


People also ask

What is a foreground window?

1. Foreground refers to the task, process, application, or window on an operating system that the user is currently using. For example, your Internet browser window that is displaying this page is the topmost window, and is considered the active foreground application.

What is an active window?

An active window is the currently focused window in the current window manager. Different window managers indicate the currently-active window in different ways and allow the user to switch between windows in different ways.

What is the current window?

Current window is a modern take of stained glass. Whilst the coloured panels of glass perform their traditional role, they also generate electricity from daylight which can then be used to power appliances indoors.


2 Answers

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).

like image 152
jamesdlin Avatar answered Sep 20 '22 19:09

jamesdlin


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.

like image 25
AndersK Avatar answered Sep 21 '22 19:09

AndersK