Solved

Find Topmost Window On Screen

Posted on 2008-10-24
5
1,581 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
ID: 22797236
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
ID: 22797325
Hi

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

Assisted Solution

by:xDJR1875
xDJR1875 earned 300 total points
ID: 22797476
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
ID: 22798436
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
ID: 31509685
Thanks guys!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

11 Experts available now in Live!

Get 1:1 Help Now