Announcement

Collapse
No announcement yet.

Setting winamp volume via API in VB6

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    My carputer

    Old one

  • #2
    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"

    Comment


    • #3
      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 =/
      My carputer

      Old one

      Comment


      • #4
        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"

        Comment


        • #5
          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
          Follow me on Twitter

          http://www.FreeICE.co.uk

          Comment


          • #6
            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"

            Comment


            • #7
              Well, since the AutoIT code worked, I'll just stick with it. Thanks! =)
              My carputer

              Old one

              Comment


              • #8
                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.

                Comment


                • #9
                  solution

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

                  then it should work.

                  Comment

                  Working...
                  X