Results 1 to 9 of 9

Thread: Setting winamp volume via API in VB6

  1. #1
    Maximum Bitrate Mañana's Avatar
    Join Date
    Jul 2004
    Location
    Sweden
    Posts
    761

    Setting winamp volume via API in VB6

    I'm trying to set the volume in winamp via an API call. I can see, via debug mode, that FindWindow gives hwndWinamp a six digit number (seems good?) and that SendMessage returns 0. The thing is, nothing happens?

    Code:
    'Declare SendMessage
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
        (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
        lParam As Long) As Long
        
    'Declare FindWindow
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
    
        Dim hwndWinamp As Long
        Dim tmp As Long
    
        hwndWinamp = FindWindow("Winamp v1.x", vbNullString)
            If hwndWinamp = 0 Then MsgBox "Couldn't find Winamp"
        
        tmp = SendMessage(hwndWinamp, WM_USER, 122, 122)
        
    End Sub

  2. #2
    Maximum Bitrate DJiK's Avatar
    Join Date
    Apr 2005
    Location
    Los Angeles (Winnetka), CA
    Posts
    864
    I'm not great with VB6 but I'm gonna try to help you anyway.

    First of all, everthing if referenced to this page.

    Looking through your code I couldn't find any value of WM_USER.
    It's a constant and must be equal to 0x400 (In VB: &H400).

    OK, now, to set the volume to a desired value between 0 and 255:
    Code:
    SendMessage(hwndWinamp, WM_USER, <volume>, 122)
    To increase volume by an increment of 1%:
    Code:
    SendMessage(hwndWinamp, WM_COMMAND, 40058, 0)
    To decrease volume by an increment of 1%:
    Code:
    SendMessage(hwndWinamp, WM_COMMAND, 40059, 0)
    *NOTE: WM_COMMAND = 0x0111 (In VB: &H111)


    Enjoy!
    For Sale: Carputer (CarPC) & RCA Y-Adapter
    Newsflash: Take a look at my unsold stuff above, thanks!
    Up Next: Make an OBD to Serial cable & Redo the "MMI buttons"

  3. #3
    Maximum Bitrate Mañana's Avatar
    Join Date
    Jul 2004
    Location
    Sweden
    Posts
    761
    I changed the code to this:

    Code:
    'Declare SendMessage
    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
        
    'Declare FindWindow
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    
    Private Sub Command1_Click()
    
        Dim hwndWinamp As Long
        Dim tmp As Long
        
        Dim WM_USER As Long
        WM_USER = &H400
        
        Dim WM_COMMAND As Long
        WM_COMMAND = &H111
    
        hwndWinamp = FindWindow("Winamp v1.x", vbNullString)
            If hwndWinamp = 0 Then MsgBox "Couldn't find Winamp"
        
        tmp = SendMessage(hwndWinamp, WM_USER, 150, 122)
        
    End Sub
    But it still doesnt work. Thou
    Code:
    SendMessage(hwndWinamp, WM_COMMAND, 40048, 0)
    works. (next file) Strange =/

  4. #4
    Maximum Bitrate DJiK's Avatar
    Join Date
    Apr 2005
    Location
    Los Angeles (Winnetka), CA
    Posts
    864
    There must be a problem with your VB code (I don't know enough to help you there).

    Here's how the program is written in AutoIt:
    Code:
    Const $WM_USER = 0x400
    
    Opt ("WinTitleMatchMode", 4)	;Sets the mode to 'classname=*' titlematch
    
    $WAhandle = ControlGetHandle("classname=Winamp v1.x", "", 0) 	;Gets the Winamp Handle
    If @error = 1 Then
    	MsgBox(16, "Fatal Error:", "Winamp not found.")
    	Exit
    EndIf
    
    $input = InputBox("Enter Volume:", "Please enter the volume you wish to set" &@CRLF&"(0 - 100%):")
    If $input >= 0 AND $input <= 100 Then
    	DllCall("user32.dll", "int", "SendMessage", "hwnd", $WAhandle, "int", $WM_USER, "int", ($input*255/100), "int", 122)	;Set the Volume to $input * 255 / 100
    Else
    	MsgBox(16, "Fatal Error:", "Value entered is not valid.")
    	Exit
    EndIf
    And here's the compiled exe file.
    For Sale: Carputer (CarPC) & RCA Y-Adapter
    Newsflash: Take a look at my unsold stuff above, thanks!
    Up Next: Make an OBD to Serial cable & Redo the "MMI buttons"

  5. #5
    FreeDrive Creator CdRsKuLL's Avatar
    Join Date
    Feb 2004
    Location
    Manchester
    Posts
    3,513
    go grab the RR source code, in there you will find a module which will allow you to do everything you want within winamp.

    CdR

  6. #6
    Maximum Bitrate DJiK's Avatar
    Join Date
    Apr 2005
    Location
    Los Angeles (Winnetka), CA
    Posts
    864
    Quote Originally Posted by CdRsKuLL View Post
    go grab the RR source code, in there you will find a module which will allow you to do everything you want within winamp.

    CdR
    Yes!
    It's called 'WinAMP_Control' -- I'm still using it as a reference every once in a while.
    For Sale: Carputer (CarPC) & RCA Y-Adapter
    Newsflash: Take a look at my unsold stuff above, thanks!
    Up Next: Make an OBD to Serial cable & Redo the "MMI buttons"

  7. #7
    Maximum Bitrate Mañana's Avatar
    Join Date
    Jul 2004
    Location
    Sweden
    Posts
    761
    Well, since the AutoIT code worked, I'll just stick with it. Thanks! =)

  8. #8
    Newbie
    Join Date
    Sep 2006
    Posts
    15

    Winamp control source code for VB6

    There is another example at http://www.industrialmightandlogic.com. Its really designed to work with Input / Output cards like the velleman k8055 or k8061 but the core of the code is simple enough (all the winamp operations are wrapped into a single class). You may want to take a look at it.

  9. #9
    Newbie
    Join Date
    Apr 2008
    Posts
    1

    solution

    add the word"ByVal" in the SendMessage declaration:
    ...ByVal lParam As Long

    then it should work.

Similar Threads

  1. Replies: 6
    Last Post: 11-12-2003, 09:57 PM
  2. How to remove winamp AVS border. - Sample VB6 code
    By Fusion-One in forum Software & Software Development
    Replies: 1
    Last Post: 10-03-2003, 07:55 PM
  3. winamp volume settings help
    By Stine161 in forum Software & Software Development
    Replies: 12
    Last Post: 07-29-2003, 10:19 PM
  4. Remember volume setting; Arist name
    By hotwater9 in forum ME Archive
    Replies: 2
    Last Post: 03-14-2003, 01:43 PM
  5. Setting windows default volume
    By surfer6262 in forum Software & Software Development
    Replies: 0
    Last Post: 08-16-2002, 02:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •