Windows C++ / GetForegroundWindow
| Author | Kyle Cucci (d4rksystem) | 
| Platform | Windows | 
| Language | C++ | 
| Technique | GetForegroundWindow | 
Description:
This technique is using the API GetForegroundWindow.
Code
#include <winuser.h> // Required import for GetForegroundWindow API
 
int main()
{
 
    //Get a handle to user's current foreground window.
    int foregroundWindowHandle1 = GetForegroundWindow(); 
 
    do {
 
        //Sleep for .1 second.
        Sleep(100); 
 
        //Get a handle to user's current foreground window again.
        int foregroundWindowHandle2 = GetForegroundWindow(); 
 
        }
 
    //While the handles to the current foreground windows are equal, continue to loop.
    while (foregroundWindowHandle1 == foregroundWindowHandle2);
 
    return 0;
};Created
October 1, 2020
Last Revised
April 22, 2024