Hey there are those that would say I'm at my best when giving "god" answers, but be that as it may....
The user32.dll:GetForegroundWindow call returns a reference to whatever window is on top, but given that reference can't you find out the name of the process that owns it? I found this code on stackoverflow that illustrates several calls.
Mike...