I'm trying to get the window that is currently on top in my
application, even if I'm currently working in another application.
Something like the P/Invoke call GetForegroundWindow(), but I want it
to operate only on my application's forms. I've also tried using
Application.OpenForms[], but I don't know how to tell which one is on
top of the others.

Any ideas?

Thanks in advance,
Cosmin

RE: get the foreground window in my application by AMercer

AMercer
Fri Feb 15 15:35:03 CST 2008

> I'm trying to get the window that is currently on top in my
> application, even if I'm currently working in another application.
> Something like the P/Invoke call GetForegroundWindow(), but I want it
> to operate only on my application's forms. I've also tried using
> Application.OpenForms[], but I don't know how to tell which one is on
> top of the others.

Probably you want is System.Windows.Forms.Form.ActiveForm. This form is not
necessarily the form that is 'on top' - see also the TopMost form property.
It is possible for a form to be topmost but not be the active form.