Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1627
  • Last Modified:

Find Topmost Window On Screen

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
angus_young_acdc
Asked:
angus_young_acdc
  • 2
  • 2
3 Solutions
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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
 
angus_young_acdcAuthor Commented:
Hi

I cant seem to add a reference to that API.  
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
angus_young_acdcAuthor Commented:
Thanks guys!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now