GetForegroundWindow doesn't work on xp

  • Thread starter Thread starter Carlos
  • Start date Start date
C

Carlos

I can not get

[ DllImport("user32.dll") ]
public static extern IntPtr GetForegroundWindow();

to work on windows xp, I always get null. It works fine on vista, I
just don't know why xp is failing.
Any ideas?
Thanks,

--Carlos
 
Carlos,

Can you provide an example? The declaration looks fine, so it probably
has something to do with where you are calling it.
 
Carlos,

Can you provide an example? The declaration looks fine, so it probably
has something to do with where you are calling it.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I can not get
[ DllImport("user32.dll") ]
public static extern IntPtr GetForegroundWindow();
to work on windows xp, I always get null. It works fine on vista, I
just don't know why xp is failing.
Any ideas?
Thanks,

There is a lot of code involved with this, I'll see if I can make a
small example. I did forget to mention one more thing, I am working on
a taskbar replacement, is there a chance it has to do with that?
 
Carlos,

Can you provide an example? The declaration looks fine, so it probably
has something to do with where you are calling it.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I can not get
[ DllImport("user32.dll") ]
public static extern IntPtr GetForegroundWindow();
to work on windows xp, I always get null. It works fine on vista, I
just don't know why xp is failing.
Any ideas?
Thanks,

Could it maybe have something to do with what this MS article
discusses:

http://support.microsoft.com/kb/118624


GetForegroundWindow() is documented to return the handle of the
foreground window, that is, the window that the user is currently
working with. The proper handle is returned when the desktop that the
application is running on is active; however, when another desktop is
active, GetForegroundWindow() returns NULL.

This is expected behavior. There is no way to get the active window in
your own desktop while another desktop is active.

The application desktop is one desktop. Other desktops include the
logon and screen saver desktops. If GetForegroundWindow() returned a
handle to the logon dialog box, it would be possible to create an
application that could get user passwords. This would violate Windows
NT security.

For this reason, it is not possible to create screen savers that melt
or drop out.
 
Hi,

Yep, that seems to be the problem. Curiously you can do it now in Vista. At
least there is something better in Vista :)

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
Carlos said:
Carlos,

Can you provide an example? The declaration looks fine, so it
probably
has something to do with where you are calling it.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I can not get
[ DllImport("user32.dll") ]
public static extern IntPtr GetForegroundWindow();
to work on windows xp, I always get null. It works fine on vista, I
just don't know why xp is failing.
Any ideas?
Thanks,

Could it maybe have something to do with what this MS article
discusses:

http://support.microsoft.com/kb/118624


GetForegroundWindow() is documented to return the handle of the
foreground window, that is, the window that the user is currently
working with. The proper handle is returned when the desktop that the
application is running on is active; however, when another desktop is
active, GetForegroundWindow() returns NULL.

This is expected behavior. There is no way to get the active window in
your own desktop while another desktop is active.

The application desktop is one desktop. Other desktops include the
logon and screen saver desktops. If GetForegroundWindow() returned a
handle to the logon dialog box, it would be possible to create an
application that could get user passwords. This would violate Windows
NT security.

For this reason, it is not possible to create screen savers that melt
or drop out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top