10
I assume that you mean the window which has the input focus when you say "active window"?
In that case, forget the GetForegroundWindow() API. That will return the topmost window - not always the window which has the input focus.
Use GetFocus() instead.