Use the GetForegroundWindow function from the the Windows API.

http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx