I am trying to control winamp 5 from a vb.net application and i have problems using SendMessage: everything seems to work except I don't get results either for WM_USER nor WM_COMMAND stuff.
It seems strange to me that the hwnd is always between something like 364673202778132480 and 372391402778132480 ...
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'function ...
Dim hwndWinamp As Long = FindWindow("waam1.2.1", vbNullString)
'having called winamp with the parameter /CLASS="waam1.2.1"
'otherwise FindWindow("winamp v1.x", vbNullString) ?
SendMessage(hwndWinamp, 273, 40029, 0) 'should pop up some window
SendMessage(hwndWinamp, 1024, 128, 122) 'should set volume to 50%
'...
'nothing works!
'
'end function
'
'btw. WM_USER=1024=h400, WM_COMMAND=273=h111
Like 4rfvgz7tdfght4 I am not getting the correct window handle back from FindWindow. The number it returns is a constantly increasing number so it clearly isn't returning the right value. Any help on figuring out why FindWindow doesn't seem to work properly would be great.
Is there any way to hook onto the play function in this API?
I'd like to intercept whenever the PLAY button is pushed, whenever the hotkey for PLAY is used, whenever PLAY is pushed on the Playlist editor, and whenever the Playback option is selected from the context menu.
Dave: you need to subclass the main window and look for the second winamp button being pressed (id is in the sdk) under the wm_command message and also the relevant key in the wm_keydown message (which covers all areas i think - no access to any of my source code at the moment but i'm sure that's what i do when i track it)
Squirrelinabox: FindWindow("Winamp v1.x","") should be working (does for me) so really not sure why the issues, maybe it's a vb thing, dunno
To 4rfvgz7tdfght4 and Squirrelinabox (If you still have trouble):
The declaration of FindWindow is wrong, it should look like this:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
The same is for SendMessage which shold look like this:
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByRef lParam As Object) As Integer
Long is used in Windows API calls when you use VB6 but not in VB.NET
Look here for Windows API reference for VB.NET.
I have done this myself in VB.NET but I changed to C# when I wanted to make a function that adds tracks to playlist due to problems with pointers.
HUGE thanks to anderslinder. That was the problem... was using Long everywhere. Somebody should add the note about using integers for .net here http://forums.winamp.com/showthread....hreadid=180297 so some people don't get mixed up like me
Everything works perfect now... thanks again, I was getting very frustrated... thought i tried everything, its those damn simple little things you overlook that bite you in the butt
Comment