Solved

Find Topmost Window On Screen

Posted on 2008-10-24
5
1,617 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

623 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