Results 1 to 6 of 6

Thread: Determine Active application

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    11

    Question Determine Active application

    Hi guys, I need to know if there is a way to determine the active application. What I mean is, how can I tell if my application has focus ???

    I wanna have a global help key for my application and I am using API function GetAsyncKeystate to trap when the user press the F1 key, the problem is, even though another application has the focus my program responds to that keystroke and my help for my app is shown.

    The app contains an MDI form and 100+ other forms(mdi-childs and standard forms).

    I am calling shellexecute to display a .pdf-helpfile whenever the user press the F1 key.

    So basicly, I want to Call a function or sub that displays my .pdf file when a user press the F1 key, regardless of which form that has got the focus, but NOT if another application has got the focus. ANY help would be appreciated.....

    thank you in advance


  2. #2
    DerFarm
    Guest
    ummmm....I don't know the answer to your question, but could
    you post the code you use to trap the keystroke from any
    focused window? This is a part of a project that I was just
    beginning to approach.


    I think I might have found it:

    Code:
    Declare Function GetActiveWindow Lib "user32.dll" () As Long 
    
    Platforms: Win 32s, Win 95/98, Win NT

    "GetActiveWindow returns a handle to your program's currently
    active window. This only works with windows created by your
    application -- in other words, it won't find the active window of
    other programs. If your program is in the background, the
    function will get the window that would be active if the program
    were active. If an error occurs, or if there is no active window to
    your program, the function instead returns 0. "


    http://www.vbapi.com/ref/g/getactivewindow.html


    Thanks.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    11

    Post

    Ok, Don't think that API will help since it will return a handle to one of my forms, even though my app is not active....

    thx, here is the code you asked for....

    Module :

    Declare Function GetAsyncKeyState Lib _
    "user32" (ByVal vKey As Long) As Integer

    Public Function Showhelp(hdInForHandle As Long)
    Dim X As Long, SW_SHOW As Long
    Dim sOp As String, sFile As String, sParam As String, sDir As String
    SW_SHOW = 5
    sOp = "open"
    sFile = C_AppPath & "Myhelp.pdf"
    sDir = Left$(C_AppPath, Len(C_AppPath) - 1)
    sParam = ""
    X = ShellExecute(ByVal hdInForHandle, ByVal sOp, ByVal sFile, ByVal sParam, ByVal sDir, ByVal SW_SHOW)
    Select Case X
    Case 0: MsgBox "Insufficient system memory or corrupt program file."
    Case 2: MsgBox "File not found."
    Case 3: MsgBox "Invalid path."
    Case 5: MsgBox "Sharing or protection error."
    Case 6: MsgBox "Separate data segments are required for each task."
    Case 8: MsgBox "Insufficient memory to run the program."
    Case 10: MsgBox "Incorrect Windows version."
    Case 11: MsgBox "Invalid program file."
    Case 12: MsgBox "Program file requires a different operating system."
    Case 13: MsgBox "Program requires MS-DOS 4.0"
    Case Is < 33: MsgBox "Could not start Acrobat."
    End Select
    End Function


    Form :
    Sub Timer1.timer()

    Dim keystate As Long ' receives key state
    keystate = GetAsyncKeyState(112) ' read the F1 key's status
    If keystate = 1 Then Showhelp (Me.hwnd)

    end sub

  4. #4
    DerFarm
    Guest
    You're right, it doesn't. On first reading, I thought that it would
    return a 0 if you are not the active window, but instead it returns
    what the active window would be IF it were active.

    Try this one:

    Code:
    Declare Function GetForegroundWindow Lib "user32.dll" () As Long
    Platforms: Win 95/98, Win NT

    "GetForegroundWindow finds which window is currently the
    foreground window. The foreground window is the window,
    usually at the top of the Z-order, with which the user is currently
    working with -- i.e., the window with the focus. The function
    returns 0 if an error occured, or the handle of the foreground
    window if successful. "


    BTW, thanks for the code, JUST what I needed!!!

    Good Luck

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    11

    bugger.... :(

    anyone else can help me with this ??? please.....

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    11

    Thumbs up YES !!!! solved

    Thanx for the help guys, I solved it........

    This really is a great forum.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width