VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox List1 
      Height          =   1230
      ItemData        =   "Form1.frx":0000
      Left            =   0
      List            =   "Form1.frx":0002
      TabIndex        =   0
      Top             =   0
      Width           =   4695
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Ok, load moi ca dans Winamp!"
      Height          =   735
      Left            =   1800
      TabIndex        =   1
      Top             =   1680
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
  "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
  ByVal ulOptions As Long, ByVal samDesired As Long, phkResult _
  As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
  "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
  String, ByVal lpReserved As Long, lpType As Long, lpData As _
  Any, lpcbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey _
  As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  ByVal lParam As Long) As Long

Public hwnd_winamp As Long

Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const KEY_QUERY_VALUE = &H1
Private Const WINAMP_REG_KEY = "WinAmp.File\shell\play\command"
Private Const WM_COMMAND = &H111
Private Const WINAMP_BUTTON4 = 40047


Private Sub Command1_Click()
    Dim PlayList As String
    
    PlayList = Form1.List1
        
    Do Until FindWinamp
        Shell GetWinampPathAndExeFile & " " & PlayList
    Loop
    
    End
End Sub

Private Sub Form_Load()
    Form1.Visible = True
    Call FindFilesOfType(".m3u", "E:\KaZaA Lite\My Shared Folder")
End Sub

Private Sub FindFilesOfType(ByVal FileType As String, Optional ByVal StartInThisFolder As String = "C:\")
    Dim SubFolderArray() As String
    Dim iSubFolder As Long
    Dim MyFolder As String
    Dim IsLogged As Boolean
    Screen.MousePointer = vbHourglass
    On Error Resume Next
    If Right$(FileType, 1) <> "," Then FileType = FileType & ","
    If Right$(StartInThisFolder, 1) <> "\" Then StartInThisFolder = StartInThisFolder & "\"
    MyFolder = Dir(StartInThisFolder & "*", vbArchive + vbHidden + vbNormal + vbReadOnly + vbSystem + vbDirectory)
    While Len(MyFolder)
        If (GetAttr(StartInThisFolder & MyFolder) And vbDirectory) = vbDirectory Then
            If Left(MyFolder, 1) <> "." Then
                ReDim Preserve SubFolderArray(iSubFolder)
                SubFolderArray(iSubFolder) = MyFolder
                iSubFolder = iSubFolder + 1
            End If
        ElseIf InStr(MyFolder, ".") Then
            If InStr(FileType, Mid$(MyFolder, InStr(MyFolder, ".")) & ",") Then
                If Not IsLogged Then
                    IsLogged = True
                End If
                List1.AddItem StartInThisFolder & MyFolder
                DoEvents
                Caption = "Logged: " & Val(Mid$(Caption, 9)) + 1
            End If
        End If
        MyFolder = Dir
    Wend
    If iSubFolder Then
        For iSubFolder = 0 To UBound(SubFolderArray)
            Call FindFilesOfType(FileType, StartInThisFolder & SubFolderArray(iSubFolder))
        Next
    End If
    Screen.MousePointer = vbDefault
End Sub
Public Function FindWinamp() As Long
    'Find winamp window
    'Returns 1 if winamp is open, 0 if not
    hwnd_winamp = FindWindow("Winamp v1.x", vbNullString)
    If hwnd_winamp Then FindWinamp = 1 Else FindWinamp = 0
End Function

Public Function GetWinampPathAndExeFile() As String
    'Finds the path of winamp
    
    Dim WinampPath As String
    
    WinampPath = RegGetString(HKEY_CLASSES_ROOT, WINAMP_REG_KEY, "")
    If Len(WinampPath) < 8 Then GetWinampPathAndExeFile = "": Exit Function
    WinampPath = Mid(WinampPath, 2, Len(WinampPath) - 7)
    GetWinampPathAndExeFile = WinampPath
End Function

Public Function RegGetString$(hInKey As Long, ByVal subkey$, ByVal valname$)
    'I got this from Microsoft's page and editted it a bit
    'Has nothing to do with winamp, you can skip it, I use
    'it in a different function
    Dim RetVal$, hSubKey As Long, dwType As Long, SZ As Long, v$, R As Long
    RetVal$ = ""
    R = RegOpenKeyEx(hInKey, subkey$, 0, KEY_QUERY_VALUE, hSubKey)
    If R <> 0 Then Exit Function
    SZ = 256
    v$ = String$(SZ, 0)
    R = RegQueryValueEx(hSubKey, valname$, 0, dwType, ByVal v$, SZ)
    If R = 0 And dwType = 1 Then
        RetVal$ = Left(v$, SZ - 1)
    Else
        RetVal$ = ""
    End If


    If hInKey = 0 Then R = RegCloseKey(hSubKey)
    RegGetString$ = RetVal$
End Function
