PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Check which application has focus
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
Check which application has focus
![]() |
Check which application has focus |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
On 22 Jun, 08:10, Christian Resma Helle <xtian...@gmail.com> 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. |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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...@gmail.com> 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. > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

