Get active window from process

  • Thread starter Thread starter Linus Rörstad
  • Start date Start date
L

Linus Rörstad

Hello!

Is there a API call to get the active window in a process? or is there
another way to solve this problem with getting the active form? The problem
is that I want one process to get the title from the active window in
another process.

Thanks
Linus
 
The first method is the easiest one - try to call GetActiveWindow:

IntPtr hwnd = GetActiveWindow();

[DllImport("coredll.dll")]
static extern IntPtr GetActiveWindow();

If it's not suitable for you (window could be inactive) the there is
the second one - you may retrieve process id for a window handle [1] and
compare it with process ID that the second application has. How to
enumerate windows in Compact Framework see Alex Yakhnin's example [2].

[1]
http://msdn.microsoft.com/library/d...ceui40/html/cerefGetWindowThreadProcessId.asp

[2]
http://blog.opennetcf.org/ayakhnin/PermaLink.aspx?guid=ce482a27-4ae9-4555-b050-827af03b7bda

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
Back
Top