Control WINAMP (VB) using Windows messages

zhaozj2021-02-16  47

Part 1: Get the window of Winamp

WINAMP is a 32-bit Windows application. That is, we can use some of the 32-bit Windows programming some basic techniques to implement WinAmp, which is the use of Windows messages. You must get the handle of the WinAmp window before you send a message to Winamp. There is a method here that uses external applications (for example, you have written VB applications) to meet the requirements.

Public Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongDim hwndWinamp as longhwndWinamp = FindWindow ( "Winamp v1.x", vbNullString)

Everyone may notice a little, why do you want to use the class name "WINAMP V1.X" to find FindWindow? Because all versions of WINAMP 1.x and 2.x are used with "Winamp v1.x" Class Name.

Part II: Using Messages

Three WINAMPs: WM_USER, WM_COMMAND, and WM_COPYDATA. WM_USER and WM_COPYDATA allow you to perform some advanced controls for WinAMP. WM_COMMAND can do some simple operations such as pause, play, and jump to the next music.

1.Wm_command message:

Previous track button 40044 Next track button 40048 Play button 40045 Pause / Unpause button 40046 Stop button 40047 Fadeout and stop 40147 Stop after current track 40157 Fast-forward 5 seconds 40148 Fast-rewind 5 seconds 40144 Start of playlist 40154 Go to end of playlist 40158 Open file dialog 40029 Open URL dialog 40155 Open file info box 40188 Set time display mode to elapsed 40037 Set time display mode to remaining 40038 Toggle preferences screen 40012 Open visualization options 40190 Open visualization plug-in options 40191 Execute current visualization plug-in 40192 Toggle About Box 40041 Toggle title Autoscrolling 40189 Toggle always on top 40019 Toggle Windowshade 40064 Toggle Playlist Windowshade 40266 Toggle doublesize mode 40165 Toggle EQ 40036 Toggle playlist editor 40040 Toggle main window visible 40258 Toggle minibrowser 40298 Toggle easymove 40186 Raise volume by 1% 40058 Lower volume by 1% 40059 Toggle Repeat 40022 Toggle Shuffle 40023 Open Jump To Time Dialog 40193 Open Jump To File Dial

og 40194 Open skin selector 40219 Configure current visualization plug-in 40221 Reload the current skin 40291 Close Winamp 40001 Moves back 10 tracks in playlist 40197 Show the edit bookmarks 40320 Adds current track as a bookmark 40321 Play audio CD 40323 Load a preset from EQ 40253 Save a preset to EQF 40254 Opens load presets dialog 40172 Opens auto-load presets dialog 40173 Load default preset 40174 Opens save preset dialog 40175 Opens auto-load save preset 40176 Opens delete preset dialog 40178 Opens delete an auto load preset dialog 40180 routines: Control WinAmp pause, play, and jump to the next music new construction, add a module, add code in the module ----------

Option expedition

Public Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPublic 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_COMMAND = & H111Const IPC_WINAMP_NextTrackButton = 40048 'skip to the next music Const IPC_WINAMP_PlayButton = 40045' play Const IPC_WINAMP_PauseUnpauseButton = 40046 'pause Public hwndWinamp As Long' handle of Winamp

Public Sub Winampplay () "Play SendMessage Hwndwinamp, WM_COMMAND, IPC_WINAMP_PLAYBUTTON, 0END SUB

Public Sub Winamppause () Pause SendMessage Hwndwinamp, WM_COMMAND, IPC_WINAMP_PAUSEUNPAUSEBUTTON, 0END SUB

Public Sub Winampnext () 'jumps to the next music SendMessage Hwndwinamp, WM_COMMAND, IPC_WINAMP_NEXTTRACKBUTTON, 0END SUB

Code added in Form ----------

Option expedition

Private Sub CmdNext_Click () Winampnext 'jumps to the next music END SUB

PRIVATE SUB CMDPAUSE_CLICK () WINAMPPAUSE 'Pause End Sub

Private subdplay_click () Winampplay 'Play End Sub

Private Sub Form_Load () HWNDWINAMP = FindWindow ("WINAMP V1.X", VBNULLSTRING) 'Get Winamp's handle if hwndwinamp = 0 THEN' Judgment WinAmp is running MSGBox "Please start Winamp first!" Unload Meend IFend Sub

2.Wm_user message:

Routines: Get a new Winamp version to create a new standard EXE project, join a module, add code in the module ----------

Option ExplicitPublic Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 'This is the API declarations VB will not return the correct results' Public Declare Function SendMessage Lib "user32" Alias "SendMessagea" (Byval Hwnd As Long, Byval WParam As Long, LParam as any) As long

'This is the correct SendMessage declaration, you can return to version information, readers can refer to the different PUBLIC DECLARE FUNCTION SendMessage Lib "User32" Alias ​​"SendMessagea" (Byval Hwnd As Long, Byval WParam As Long, ByVal LPARAM As Long) As long

Const wm_user = & h400const wa_getversion = 0PUBLIC HWNDWINAMP AS long 'WinAmp handle

Function WinampgetVersion () AS STRINGDIM VERSIONNUM AS LONGDIM RETURNVERSION AS STRINGVERSIONNUM = SendMessage (HWndwinAmp, WM_USER, 0, WA_GETVERSION)

IF LEN (HEX (VersionNum)> 3 Ten Returnversion = Left (HEX (VersionNum), 1) & "." Returnversion = Returnversion & Mid (HEX (VersionNum), 2, 1) Returnversion = RETURNVERSION & RIGHT $ (HEX VersionNum) - 3) WINAMPGETVERSION = Returnvelse WINAMPGETVERSION = "unknown" End IFEND FUNCTION Added in Form ----------------

Option expedition

Private submmand1_click () msgbox "Your WINAMP version is:" & WinampgetVersionend Sub

Private Sub Form_Load () HWNDWINAMP = FindWindow ("WINAMP V1.X", VBNULLSTRING) 'Get Winamp's handle if hwndwinamp = 0 THEN' Judgment WinAmp is running MSGBox "Please start Winamp first!" Unload Meend IFend Sub

3.Wm_copyData message:

Routines: Winamp's runtime joins a MP3 song to create a standard EXE project in the playlist, join a module, add code in the module ----------

Option expedition

Public Declare Function FindWindow Lib "user32" Alias ​​"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function lstrcpy Lib "kernel32" Alias ​​"lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As LongPrivate Declare Function CopyDataSendMessage Lib "user32" Alias ​​"SendMessageA" (ByVal WndID As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As COPYDATASTRUCT) As LongPrivate Type COPYDATASTRUCT dwData As Long cbData As Long lpData As LongEnd Type

Const IPC_PlayFile = 100Const WM_CopyData = & H4A

Public HWNDWINAMP AS Long

Public Sub WinampAddSong (SongName As String) Dim CDS As COPYDATASTRUCTWith CDS .dwData = IPC_PLAYFILE .cbData = 100 .lpData = lstrcpy (SongName, SongName) End WithCopyDataSendMessage hwndWinamp, WM_COPYDATA, 0 &, CDSEnd Sub code added in the Form ---- --------

Option expedition

Private Sub Command1_Click () Winampaddsong "i: / mp3 / Jay Chou - Simple Love. MP3" Add a song END SUB

Private Sub Form_Load () HWNDWINAMP = FindWindow ("WINAMP V1.X", VBNULLSTRING) 'Get Winamp's handle if hwndwinamp = 0 THEN' Judgment WinAmp is running MSGBox "Please start Winamp first!" Unload Meend IFend Sub

All routines are debugged in Win2000 VB6

转载请注明原文地址:https://www.9cbs.com/read-27513.html

New Post(0)