Results 1 to 6 of 6

Thread: How to find a running application?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    2

    Question How to find a running application?

    Hi Everybody,

    I need your help. Actually I want to find whether an application is open and if open, the window of that app. should get focus and be restored to normal position.

    How can i do this.

    Thanks in advance.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    By "Open" I assume you mean running. Here is an example that should work for you.
    VB Code:
    1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    2. Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    3. Private Const SW_SHOWNORMAL = 1
    4.  
    5. Private Sub Command1_Click()
    6.     Dim WinWnd As Long
    7.     WinWnd = FindWindow(vbNullString, "Calculator")
    8.     If WinWnd > 0 Then
    9.        'Calculator Is Running - restore it to normal position
    10.        ShowWindow WinWnd, SW_SHOWNORMAL
    11.     End If
    12. End Sub

  3. #3
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    When using FindWindow, it's a good idea to specify a classname as well (just to help narrow down your search).

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Originally posted by Megatron
    When using FindWindow, it's a good idea to specify a classname as well (just to help narrow down your search).
    Good point!

  5. #5
    New Member
    Join Date
    Sep 2002
    Posts
    5
    Hey there,
    But how can I find who was the last window who has the focus BEFORE I click on my form and my form has the focus? Is there any way? Thank you.

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    2

    Re: How to find a running application?

    Thank you very much for the help. I tried using the code in my application. I have one problem. The hWnd, returned by the FindWindow function is always -1. So ShowWindow function is not working. I have not used the classname in the FindWindow function. Will, using the classname will solve my problem? By classname u mean, the Form name?

    With regards,
    Surfy.

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