Use Windows message to control WinAmp (Delphi) ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------- Part 1: Get winamp's window
WINAMP is a 32-bit Windows application. In other words, we can use 32-bit Windows programming some basic technologies to implement control
WINAMP, that is, using Windows message system. You must get the handle of the WinAmp window before you send a message to Winamp. here has
Method, use external applications (eg, yourself writing Delphi app) can reach the requirements.
Var hwndwinamp: hwnd; hwndwinamp: = findwindow ('Winamp v1.x', 0); // Get WinAmp handle
Everyone may notice a little, why do you want to use the class name "WINAMP V1.X" to find FindWindow? Because WinAmp 1.x and 2.x all
The version is 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
WINAMP performs some advanced controls. 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 unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;
Const IPC_WINAMP_NEXTTRACKBUTTON: INTEGER = 40048; // Skip to the next music const IPC_WINAMP_PLAYBUTTON: INTEGER = 40045; // Play const IPC_WINAMP_PAUSEUNPAUSEBUTTON: INTEGER = 40046; // Pause
type TForm1 = class (TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure FormCreate (Sender: TObject); procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); procedure Button3Click (Sender: TObject) PRIVATE {Private Declarations}}
Var Form1: TForm1; Hwndwinamp: Hwnd; // WinAmp window handle IMPLEMentation
{$ R * .dfm}
procedure TForm1.FormCreate (Sender: TObject); beginhwndWinamp: = FindWindow ( 'Winamp v1.x', 0); // get a handle Winamp If hwndWinamp = 0 Then // determines whether the operation Winamp begin ShowMessage ( 'start to Winamp ! '); Application.Terminate; endnd; procedure tform1.button1click (sender: TOBJECT); Begin // Let WinAmp jump to the next music SendMessage (HWndwinAmp, WM_COMMAND, IPC_WINAMP_NEXTTRACKBUTTON, 0); END;
Procedure tForm1.Button2Click (Sender: Tobject); Begin / / Let Winamp play current MP3sendMessage (hwndwinamp, wm_command, ipc_winamp_playbutton, 0);
Procedure TForm1.Button3Click (Sender: Tobject); Begin / / Let WinAmp 3sendMessage (HwndwinAmp, WM_COMMAND, IPC_WINAMP_PAUSEUNPAUSEBUSEBUTTON, 0);
End.
2.Wm_user message:
Routine: get Winamp version
Unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls, Strutils; // Using Strutils to use LEFTSTR, Rightstr, Midstr, MiDSTR and other functions
Const Wa_getVersion: INTEGER = 0; // WinAmp version
type TForm1 = class (TForm) Button1: TButton; procedure FormCreate (Sender: TObject); procedure Button1Click (Sender: TObject); private {Private declarations} public {Public declarations} end;
Var Form1: TForm1; Hwndwinamp: Hwnd; // WinAmp window handle IMPLEMentation
{$ R * .dfm}
procedure TForm1.FormCreate (Sender: TObject); beginhwndWinamp: = FindWindow ( 'Winamp v1.x', 0); // get a handle Winamp If hwndWinamp = 0 Then // determines whether the operation Winamp begin ShowMessage ( 'start to Winamp ! '); Application.Terminate; Endend;
procedure TForm1.Button1Click (Sender: TObject); var VersionNum: integer; ReturnVersion: String; beginVersionNum: = SendMessage (hwndWinamp, WM_USER, 0, WA_GETVERSION); If Length (IntToHex (VersionNum, 4))> 3 Thenbegin ReturnVersion: = LeftStr (INTTOHEX (VersionNum, 4), 1) '; Returnversion: = Returnversion Midstr (INTTOHEX (VersionNum, 4), 2, 1); RTURNVERSION: = RETURNVERSION Rightstr (INTTOHEX (VersionNum, 4), Length INTTOHEX (VersionNum, 4)) - 3); endelse returnversion: = 'unknown';
ShowMessage (Returnversion);
End.
3.Wm_copyData message:
Routines: Winamp's runtime joins a MP3 song in the playlist
Unit unit1;
Interface
Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;
Const IPC_PlayFile: INTEGER = 100; // WinAmp Add files
type TForm1 = class (TForm) Button1: TButton; procedure FormCreate (Sender: TObject); procedure Button1Click (Sender: TObject); private {Private declarations} public {Public declarations} end;
Var Form1: TForm1; Hwndwinamp: Hwnd; // WinAmp window handle IMPLEMentation
{$ R * .dfm}
procedure TForm1.FormCreate (Sender: TObject); beginhwndWinamp: = FindWindow ( 'Winamp v1.x', 0); // get a handle Winamp If hwndWinamp = 0 Then // determines whether the operation Winamp begin ShowMessage ( 'start to Winamp ! '); Application.Terminate; Endend;
procedure TForm1.Button1Click (Sender: TObject); var CDS: COPYDATASTRUCT; SongName: String; beginSongName: = 'I: / Mp3 / Jay - Simple Love .mp3'; CDS.dwData: = IPC_PLAYFILE; CDS.cbData: = Length ( SongName) 1; cds.lpdata: = pchar (songname); sendMessage (hwndwinamp, wm_copydata, 0, integer (@cds));
End.
All routines are debugged in Win2000 Delphi6