Solved

Find Topmost Window On Screen

Posted on 2008-10-24
5
1,571 Views
Last Modified: 2013-12-17
I am trying to create a small app whereby I can monitor what is going on in a desktop.  What I'm currently stuck on is how to find out what is the topmost app running in the system.  For example is Internet Explorer the topmost?  Or Visual Studio, etc.

I figure I may need a hook but I'm not sure where to begin on that.  Or how to actually find out what is the top most!
0
Comment
Question by:angus_young_acdc
  • 2
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
xDJR1875 earned 300 total points
Comment Utility
The win32 API call of GetActiveWindow is what I think I recall using once upon a time.

It apparently now can be replaced by the following
GetActiveWindow Retrieves the window (handle to the active window attached to the calling thread's message queue.)
System.Windows.Forms.Form.ActiveForm

see this link for more info
http://msdn.microsoft.com/en-us/library/aa302340.aspx#win32map_alphalist
0
 
LVL 15

Author Comment

by:angus_young_acdc
Comment Utility
Hi

I cant seem to add a reference to that API.  
0
 
LVL 17

Assisted Solution

by:xDJR1875
xDJR1875 earned 300 total points
Comment Utility
Most of the functionality of the win32 api is also covered in the .NET framework. Try using .NET before reverting to the win32 api.

the link above contains a mapping of what win32 api call is now replaced by a .NET api call, so try using that first.... Otherwise,

Check these links out for info on using the win32 api in .NET
http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=96
http://episteme.arstechnica.com/eve/forums/a/tpc/f/6330927813/m/2830976345
0
 
LVL 85

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 200 total points
Comment Utility
You want GetForegroundWindow():
http://msdn.microsoft.com/en-us/library/ms633505(VS.85).aspx

    "The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). "

It would look like:

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

The ClassName of the foreground window may also be of interest to you.  The GetClassName() API is used in this PAQ:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21611201.html#15181322

0
 
LVL 15

Author Closing Comment

by:angus_young_acdc
Comment Utility
Thanks guys!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now