Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

GetForegroundWindow doesn't work on xp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlos - 07 Nov 2007 16:34 GMT
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
Nicholas Paldino [.NET/C# MVP] - 07 Nov 2007 16:44 GMT
Carlos,

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

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

>I can not get
>
[quoted text clipped - 7 lines]
>
> --Carlos
Carlos - 07 Nov 2007 17:08 GMT
On Nov 7, 10:44 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Carlos,
>
[quoted text clipped - 16 lines]
>
> > --Carlos

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 - 07 Nov 2007 17:26 GMT
On Nov 7, 10:44 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
> Carlos,
>
[quoted text clipped - 16 lines]
>
> > --Carlos

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.
Ignacio Machin ( .NET/ C# MVP ) - 07 Nov 2007 18:00 GMT
Hi,

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

Signature

Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

> On Nov 7, 10:44 am, "Nicholas Paldino [.NET/C# MVP]"
> <m...@spam.guard.caspershouse.com> wrote:
[quoted text clipped - 42 lines]
> For this reason, it is not possible to create screen savers that melt
> or drop out.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.