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.
Printable View
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.
Welcome to the forums. :wave:
Are you talking about a Task Manager type application that can list all open applications?
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.
GetForegroundWindow()
Sample usage:
VB Code:
Declare Function GetForegroundWindow Lib "user32" () As Long Declare Function GetWindowText Lib "user32" Alias "GetWindowTextW" ( _ ByVal hWnd As Long, _ ByVal lpString As Long, _ ByVal nMaxCount As Long _ ) As Long Function GetActiveWindowName() As String GetActiveWindowName = String$(255) GetWindowText GetForegroundWindow(), StrPtr(GetActiveWindowName), 255 GetActiveWindowName = Trim$(GetActiveWindowName) End Function
How would I display the information in a label or list?
That's the trivial part...
VB Code:
Label1.Caption = GetActiveWindowName()
Can you send me a zip of this working? I just want to see if it all really does work. It didnt for me.