|
-
Mar 20th, 2000, 10:47 AM
#1
Thread Starter
Member
Ok I have a rather complicated question:
In VB, how can I find out the window title of another application running at the same time using the Windows API?
I tried "GetWindowText" but that only works for windows in that VB application.
The reason I'm asking is because I want to get the title of WinAmp while it's running because it shows the current song playing and I need the program to know that.
If you have another way please tell!
-
Mar 21st, 2000, 02:25 AM
#2
GetWindowText works for windows outside of your application to.
The problem is that you need the windowhandle of that window.
One way of finding this is by using the FindWindow API.
In order to use this function, you need to know either the windowtext (and this is what we don't know) or the windowclass.
Using Spy++ it is easy to find this out. And with Winamp we are lucky. It has an easy to recognize classname.
With the winamp version I'm using this is 'Winamp v1.x', I'm downloading a newer version right now, so I assume the classname will be 'Winamp v2.x' now.
This makes the possibily of two open windows with the same classname not so big.
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Command1_Click()
Dim retVal As Long
Dim sTitle As String
Dim hWinAmp As Long
hWinAmp = FindWindow("Winamp v1.x", vbNullString)
If hWinAmp <> 0 Then
sTitle = Space(256)
retVal = GetWindowText(hWinAmp, sTitle, 255)
MsgBox sTitle
End If
End Sub
[Edited by Frans C on 03-21-2000 at 02:27 PM]
-
Mar 21st, 2000, 04:39 AM
#3
I just downloaded winamp v2.61 and after a first test the classname still appeared to be 'Winamp v1.x'
After having a look at the version history, i found out that they added a commandline option that can change the classname of the window.
This enables users, who don't want to be bothered by programs like yours, to change the classname of the window, making finding the windows handle a bit difficult.
The commandline option is: /CLASS="Frans C"
You can change the Frans C of course.
-
Mar 21st, 2000, 04:51 AM
#4
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|