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

Re: Control.FromHandle by Dmitriy

Dmitriy
Mon Dec 15 04:54:16 CST 2003

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.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Bijoy Thulasidharan" <bijoy.thulasidharan@dewr.gov.au.nospam> wrote in
message news:3fdd2f88$1@info-mid...
> 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
>
>
>
>
>
>
>
>
>


Re: Control.FromHandle by hirf-spam-me-here

hirf-spam-me-here
Mon Dec 15 06:15:26 CST 2003

* "Bijoy Thulasidharan" <bijoy.thulasidharan@dewr.gov.au.nospam> scripsit:
> 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/groups?selm=eMOnRdemDHA.3732%40tk2msftngp13.phx.gbl>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Re: Control.FromHandle by hirf-spam-me-here

hirf-spam-me-here
Mon Dec 15 06:13:54 CST 2003

* "Bijoy Thulasidharan" <bijoy.thulasidharan@dewr.gov.au.nospam> scripsit:
> 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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Re: Control.FromHandle by Bijoy

Bijoy
Mon Dec 15 16:13:38 CST 2003

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



"Bijoy Thulasidharan" <bijoy.thulasidharan@dewr.gov.au.nospam> wrote in
message news:3fdd2f88$1@info-mid...
> 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
>
>
>
>
>
>
>
>
>