How to get the Process the Active Proces?

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

In my VB.NET-application I need to get the Process that is currently active
on the screen of the user. I need it to get back to that application after
that I brought mine to the front...

for exemple: user types in Word...
my application triggers an event, has to come to the foreground (when it is
minimzed)
immediately after that the Word-process has to be set again to the front so
the user can continu typing in word (and not in my application).

I don't think Process.GetCurrentProcess is the good answer, because that
points always to my VB.NET-application.

Thanks a lot in advance,

Pieter
 
Get the top window. There are a number of ways to do it. I am looking at an
MSDN article entitled 'Windows' from 'Windows Management' and they have
calls that can get a handle to the top window and calls that can bring a
window to the top. Two calls:

GetTopWindow
BringWIndowToTop

should do it. (No, I haven't doen this in windows but I have in other GUI
OSes.
 
I doubt you being able to do so just through .NET framework. You might need
to use a system wide hook on the keyboard events and use
GetForegroundWindow() and follow it up to find the Process who owns that
handle (GetWindowThreadProcessId()) and find the process that way.
Of course, I am talking only about PInvoked methods. I dont know if there
are any direct mappings to .NET classes. You might be able to find PInvoke
signatures at www.pinvoke.net.
 
Back
Top