views:

33

answers:

2

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:

http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#foreground

+1  A: 

I think what they with mean foreground is "top most" as opposed to having a window in the background which typically is behind other windows. An active window can be any window whether it is behind other windows (annoying) or in the foreground (top most)

EDIT: when a window is active all input like keyboard is directed to it.

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

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

/----------------------\
|                      |
|   FOREGROUND WINDOW  |--\
|                      |  |
\----------------------/  |
  | ACTIVE WINDOW         |
  \------------------------/
Anders K.
Microsoft said that, a foreground window (belong foreground thread) is given more priority. In your 3rd case, Is ACTIVE WINDOW received same privilege?
pinichi
msdn's description of 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.*So is it possible to have the 3rd case given above?
JavaMan
Yes, it's possible. An Alway On Top window (has WS_EX_TOPMOST) can overlap an active window (title bar blur, select text not hightling, text cursor...though)
pinichi
A: 

After read the MSDN, I feel confusing:

  1. Foreground window (belong foreground thread) is given more priority is the window user are working with
  2. Active window: top-level, receive input focus.
  3. A top-most window is always overlap others whether if it is a foreground or active. Very hard to conclusions:
  1.Foreground is always topmost?
  2.Active window is also Foreground (priority not clear?)?

PS: I try to read about GetActiveWindow , GetForegroundWindow but more over confuse.
GetForegroundWindow : globaly (all threads) get current window user are working with (active or not?). Some times return null (from many replies)
GetActiveWindow: get the most on top window created by calling thread, if thread not foreground it return null.

Sorry because of more confusing I made.

pinichi