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 ...

+ Reply to Thread
Results 1 to 5 of 5

Check which application has focus

  1. Default 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.


  2. Default 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


  3. Default 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.


  4. Default 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.
    >




  5. Default 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



+ Reply to Thread

Similar Threads

  1. Visual C# App - When form application loads, do not take focus
    By Application Development in forum CSharp
    Replies: 0
    Last Post: 08-06-2007, 08:12 PM
  2. Event raised when Application/Form regains focus...
    By Application Development in forum CSharp
    Replies: 17
    Last Post: 08-03-2007, 05:35 PM
  3. Check box focus problem on smartphone
    By Application Development in forum DOTNET
    Replies: 3
    Last Post: 06-25-2007, 11:56 AM
  4. Help - Eudora now stealing focus on every check
    By Application Development in forum Eudora
    Replies: 5
    Last Post: 03-19-2007, 12:39 PM
  5. focus/lost focus of custom control
    By Application Development in forum Inetserver
    Replies: 1
    Last Post: 11-21-2003, 10:18 AM