You can try the GetForegroundWindow API.