Control.FromHandle

  • Thread starter Bijoy Thulasidharan
  • Start date
B

Bijoy Thulasidharan

Hi ,
We are trying to obtain the active window of a given Windows Forms
application . Although most of the win API functions like GetActiveWindow
and
GetForegroundWindow return a valid handle , calling the method
Control.FromHandle using the handle returned from the WIN API evaluates to
null.

All we are interested in is in checking whether a specific winform
application is running or not ( Ofcourse we could have used WSH but we need
to do a bit more than what can be achieved with that) through a monitoring
application
Any sample illustrations or alternative approaches would be highly regarded

Kind Regards

Bijoy
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Using named mutexes is, I believe, the most common and correct approach to
determine whether an instance is running. Do the Google group search on
"named mutex application instance" within the microsoft.public.dotnet.*
hierarchy, this topic has been discussed many times before.
 
H

Herfried K. Wagner [MVP]

* "Bijoy Thulasidharan said:
We are trying to obtain the active window of a given Windows Forms
application . Although most of the win API functions like GetActiveWindow
and
GetForegroundWindow return a valid handle , calling the method
Control.FromHandle using the handle returned from the WIN API evaluates to
null.

I am not sure at the moment, but AFAIR this will only work with controls
in the /same/ instance of the application.
 
H

Herfried K. Wagner [MVP]

* "Bijoy Thulasidharan said:
All we are interested in is in checking whether a specific winform
application is running or not ( Ofcourse we could have used WSH but we need
to do a bit more than what can be achieved with that) through a monitoring
application
Any sample illustrations or alternative approaches would be highly regarded

Have a look at Tom Shelton's solution here:

<http://groups.google.com/[email protected]>
 
B

Bijoy Thulasidharan

Thanks to all your responses. Using the Mutex class appears to the cleanest
way to monitor whether an instance of an application is running or no. Cool
Indeed.
Although we still need to be able to say whether the main Form in the
Application (MDI FORM) is alive or not.

The reason y we are trying to do this is ,
1. The application crashes at times , and the monitor application is
expected to restart the application whenever something like that happened
which should now be possible through the Mutex approach you guys suggested
2. Although While crashing at times the process remains in memory and
just the Application Window disappears, hence our need to check whether the
application Main window handle exists or not

Kind Regards

Bijoy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top