Solved

Find Topmost Window On Screen

Posted on 2008-10-24
5
1,592 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:
Daniel Reynolds 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:Daniel Reynolds
Daniel Reynolds 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 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