Check which application has focus - DOTNET
This is a discussion on Check which application has focus - DOTNET ; Hi.
we have a WM5 device, with several applications running. is it
possible for one of our applications running on this device ( vb .net
cf2) to identify which program has "focus" on the device (which app
the user is ...
-
Check which application has focus
Hi.
we have a WM5 device, with several applications running. is it
possible for one of our applications running on this device (vb.net
cf2) to identify which program has "focus" on the device (which app
the user is seeing on the screen)??
is there any environment or registry settings i can look at?
Ian.
-
Re: Check which application has focus
Hi Ian,
You can P/Invoke a method called GetForegroundWindow() from
coredll.dll and compare the handle you get with the handle of your
applications main form.
To call GetForegroundWindow() you would have to use DllImport
<DllImport("coredll.dll")> _
Private Shared Function GetForegroundWindow() As IntPtr
End Function
In your main form compare Me.Handle with the IntPtr you get from
GetForegroundWIndow()
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
-
Re: Check which application has focus
On 22 Jun, 08:10, Christian Resma Helle <xtian...> wrote:
> Hi Ian,
>
> You can P/Invoke a method called GetForegroundWindow() from
> coredll.dll and compare the handle you get with the handle of your
> applications main form.
>
> To call GetForegroundWindow() you would have to use DllImport
>
> <DllImport("coredll.dll")> _
> Private Shared Function GetForegroundWindow() As IntPtr
> End Function
>
> In your main form compare Me.Handle with the IntPtr you get from
> GetForegroundWIndow()
>
> Regards,
> Christian Resma Hellehttp://christian-helle.blogspot.com
Thanks. I'll give this a go. Can this info tell me the name of the
application in the foreground? I only want to swap back to "my"
application on certain occasions - i need to allow some apps into the
foreground.
Ian.
-
Re: Check which application has focus
Define "name of the application"! If you want the title of the window, yes,
you can call GetWindowText() on it and you'll get the title. If you mean
the name of the EXE that launched it, no (not that a user couldn't just as
easily change the name of any EXE, anyway). If you own the applications in
question, you'd be better off coming up with some way for them to
communicate with one another when it's time for you to come to the front.
Paul T.
"vsciw" <ian.watkins@vscsolutions.com> wrote in message
news:1182505545.967133.229420@o61g2000hsh.googlegroups.com...
> On 22 Jun, 08:10, Christian Resma Helle <xtian...> wrote:
>> Hi Ian,
>>
>> You can P/Invoke a method called GetForegroundWindow() from
>> coredll.dll and compare the handle you get with the handle of your
>> applications main form.
>>
>> To call GetForegroundWindow() you would have to use DllImport
>>
>> <DllImport("coredll.dll")> _
>> Private Shared Function GetForegroundWindow() As IntPtr
>> End Function
>>
>> In your main form compare Me.Handle with the IntPtr you get from
>> GetForegroundWIndow()
>>
>> Regards,
>> Christian Resma Hellehttp://christian-helle.blogspot.com
>
> Thanks. I'll give this a go. Can this info tell me the name of the
> application in the foreground? I only want to swap back to "my"
> application on certain occasions - i need to allow some apps into the
> foreground.
>
> Ian.
>
-
Re: Check which application has focus
Following up on Paul's advice, here's a sample of p/invoking GetWindowText()
<DllImport("coredll.dll")>
Private Shared Function GetWindowText( _
ByVal hWnd As IntPtr, _
ByVal lpString As StringBuilder, _
ByVal nMaxCount As Integer) As Integer
End Function
--
Regards,
Christian Resma Helle
http://christian-helle.blogspot.com
Similar Threads
-
By Application Development in forum CSharp
Replies: 0
Last Post: 08-06-2007, 08:12 PM
-
By Application Development in forum CSharp
Replies: 17
Last Post: 08-03-2007, 05:35 PM
-
By Application Development in forum DOTNET
Replies: 3
Last Post: 06-25-2007, 11:56 AM
-
By Application Development in forum Eudora
Replies: 5
Last Post: 03-19-2007, 12:39 PM
-
By Application Development in forum Inetserver
Replies: 1
Last Post: 11-21-2003, 10:18 AM