How can I find WinAmp Main window, and send the key 'x' to it??
Printable View
How can I find WinAmp Main window, and send the key 'x' to it??
Code:Private Sub Command1_Click()
AppActivate ("Winamp")
SendKeys "x"
End Sub
you could use FindWindow and the classname to get the hwnd, then use SendMessageByString and send "x" to it, this would be more reliable.
Code:Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Could you give an example on how to use it....i can't get it to work....
I couldnt get it to work either, thats why I didnt post a sample :p
ok! : o )
Send the WM_CHAR message:
Code:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CHAR = &H102
Private Sub Command1_Click()
Dim hWinamp As Long
'Get the hWnd of Winamp
hWinamp = FindWindow("Winamp v1.x", vbNullString)
'Send the X button to Winamp
SendMessage hWinamp, WM_CHAR, vbKeyX, 0
End Sub
Hi megatron!
Nothing happens....
I already tried that!
I tried using WM_KEYDOWN and WM_KEYUP and WM_CHAR nothing worked.
I have also looked at the SendKeys help topic in VB....didn't work either!
Try this. I've used WM_KEYDOWN instead.
Code:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_KEYDOWN = &H100
Private Sub Command1_Click()
Dim hWinamp As Long
'Get the hWnd of Winamp
hWinamp = FindWindow("Winamp v1.x", vbNullString)
'Send the X button to Winamp
SendMessage hWinamp, WM_KEYDOWN, vbKeyX, 0
End Sub
I tried the SendKeys code myself, it worked fine.
but winamp has to be open first..(obviously)
Thanks Megatron! That worked!