Results 1 to 7 of 7

Thread: Knowing what applications are running

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    15

    Question Knowing what applications are running

    Is there a way for your program to know what other applications are running and what application has the focus at a given time? Perhaps getting the current form name of the application that has the focus.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Knowing what applications are running

    Welcome to the forums.

    Are you talking about a Task Manager type application that can list all open applications?

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    15

    Re: Knowing what applications are running

    Not really a task manager. I want my program to be able to tell what program has focus. What the program name is. Im guessing it can get that from a API? Once it does to store it in a variable and desplay it in a text box or something. I dont want it to be able to see any other programs at the time. Just the one that is currently being used.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Knowing what applications are running

    GetForegroundWindow()

    Sample usage:
    VB Code:
    1. Declare Function GetForegroundWindow Lib "user32" () As Long
    2.  
    3. Declare Function GetWindowText Lib "user32" Alias "GetWindowTextW" ( _
    4.     ByVal hWnd As Long, _
    5.     ByVal lpString As Long, _
    6.     ByVal nMaxCount As Long _
    7. ) As Long
    8.  
    9. Function GetActiveWindowName() As String
    10.     GetActiveWindowName = String$(255)
    11.     GetWindowText GetForegroundWindow(), StrPtr(GetActiveWindowName), 255
    12.     GetActiveWindowName = Trim$(GetActiveWindowName)
    13. End Function
    Last edited by penagate; Dec 1st, 2005 at 06:50 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    15

    Re: Knowing what applications are running

    How would I display the information in a label or list?

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Knowing what applications are running

    That's the trivial part...

    VB Code:
    1. Label1.Caption = GetActiveWindowName()

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2005
    Posts
    15

    Re: Knowing what applications are running

    Can you send me a zip of this working? I just want to see if it all really does work. It didnt for me.

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