471,305 Members | 1,120 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,305 software developers and data experts.

Detecting which application currently has focus...

I am trying to write a piece of code, which will tell me which application
currently has focus / which the user is currently working on. ie. if the
user is currently in IE, or Word etc....

How can I find this in .NET?

Dec 1 '05 #1
1 1241
>How can I find this in .NET?

Call the GetForegroundWindow Win32 API to get the window handle for
the foreground window. You can then for example call
GetWindowThreadProcessId to get the process that created the window.
And then use the process ID to retrieve any information you need about
the application.

Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Dec 1 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.