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.
Each thread has a priority level that determines the amount of CPU time the thread receives. Although an application can set the priority level of its threads, normally the foreground thread has a slightly higher priority level than the background threads. Because it has a higher priority, the foreground thread receives more CPU time than the background threads. The foreground thread has a normal base priority of 9; a background thread has a normal base priority of 7.
The user sets the foreground window by clicking a window, or by using the alt+tab or alt+esc key combination. An application sets the foreground window by using the SetForegroundWindow function. If the new foreground window is a top-level window, the system activates it; otherwise, it activates the associated top-level window. An application retrieves a handle to the foreground window by using the GetForegroundWindow function. To check if your application window is active, compare the handle returned by GetForegroundWindow to that of your application window.