引用WAint.pas操控WINAMP,很方便!
(* This unit will allow control of Nullsofts awesome Mp3 Player
* Winamp from within Delphi 2 &
3 Applications. This unit is FREEWARE;
if you
* like it or have any questions about it let me know emslie@gpu.srv.ualberta.ca
*)
unit WAInt;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
FileCtrl, StdCtrls, Spin;
Const
{WM_WA_IPC = WM_USER;}
IPC_GETVERSION = 0;
IPC_PLAYFILE = 100;
IPC_DELETE = 101;
IPC_STARTPLAY = 102;
IPC_CHDIR = 103;
IPC_ISPLAYING = 104;
IPC_GETOUTPUTTIME = 105;
IPC_JUMPTOTIME = 106;
IPC_WRITEPLAYLIST = 120;
WINAMP_OPTIONS_EQ = 40036;
WINAMP_OPTIONS_PLEDIT = 40040;
WINAMP_VOLUMEUP = 40058;
WINAMP_VOLUMEDOWN = 40059;
WINAMP_FFWD5S = 40060;
WINAMP_REW5S = 40061;
WINAMP_BUTTON1 = 40044;
WINAMP_BUTTON2 = 40045;
WINAMP_BUTTON3 = 40046;
WINAMP_BUTTON4 = 40047;
WINAMP_BUTTON5 = 40048;
WINAMP_BUTTON1_SHIFT = 40144;
WINAMP_BUTTON2_SHIFT = 40145;
WINAMP_BUTTON3_SHIFT = 40146;
WINAMP_BUTTON4_SHIFT = 40147;
WINAMP_BUTTON5_SHIFT = 40148;
WINAMP_BUTTON1_CTRL = 40154;
WINAMP_BUTTON2_CTRL = 40155;
WINAMP_BUTTON3_CTRL = 40156;
WINAMP_BUTTON4_CTRL = 40157;
WINAMP_BUTTON5_CTRL = 40158;
WINAMP_PREVSONG = 40198;
WINAMP_FILE_PLAY = 40029;
WINAMP_OPTIONS_PREFS = 40012;
WINAMP_OPTIONS_AOT = 40019;
WINAMP_HELP_ABOUT = 40041;
Procedure GetVersion;
{IPC_GETVERSION is sent to the window, and the return value is the version
Version 1.55 = 0x1551
Version 1.6b = 0x16A0
Version 1.60 = 0x16AF
Version 1.61 = 0x16B0
Version 1.62 = 0x16B1
Version 1.64 = 0x16B3
Version 1.666 = 0x16B4
Version 1.69 = 0x16B5
Version 1.70 = 0x1700
Version 1.72 = 0x1702
Version 1.72 = 0x1703
the command_data parameter is 0. }
procedure AddMp3ToPlayList(mp3ToAdd:string);
Procedure DeletePlayList;
Procedure StartPlay;
Procedure ChangeDir(DirToChangeTo:string);
Function PlayBackStatus : integer;
{ IPC_ISPLAYING returns the status of playback.
If it returns 1, it is playing. if it returns 3, it is paused, if it returns 0, it is not playing.
If it returns something other than 1,3,or 0, something is screwed.
}
Function GetOutPutTime( x : integer): Integer;
{ IPC_GETOUTPUTTIME returns the position in milliseconds of the
current song (lParam = 0), or the song length, in seconds (lParam = 1).
Returns -1 if not playing or error.}
function JumpToTime(new_song_pos:integer):integer;
{ *ONLY AVAILABLE IN v1.60+*
IPC_JUMPTOTIME sets the position in milliseconds of the current song (approximately)
Returns -1 if not playing, 1 on eof, or 0 if successful }
Function WritePlaylist : Integer;
{ *ONLY AVAILABLE IN v1.666+*
IPC_WRITEPLAYLIST writes the current playlist to <winampdir>//Winamp.pl }
// THESE MIGHT CHANGE in the future
//Also, you can send standard WM_COMMAND messages to the Winamp window (for other controls), including
// Send using SendMessage(hwnd_winamp,WM_COMMAND,WINAMP_OPTIONS_EQ/*orwhatever*/,0);
Procedure EQ;
// toggles the EQ window
Procedure PlayList;
// toggles the playlist window
Procedure VolumeUp;
// turns the volume up a little
Procedure VolumeDown;
// turns the volume do
wn a little
Procedure Forward5;
// fast forwards 5 seconds
Procedure Rewind5;
// rewinds 5 seconds
// the following are the five main control buttons, with optionally shift or control pressed
// (for the exact functions of each, just try it out)
Procedure Button1;
Procedure Button2;
Procedure Button3;
Procedure Button4;
Procedure Button5;
Procedure Button1_Shift;
Procedure Button2_Shift;
Procedure Button3_Shift;
Procedure Button4_Shift;
Procedure Button5_Shift;
Procedure Button1_CTRL;
Procedure Button2_CTRL;
Procedure Button3_CTRL;
Procedure Button4_CTRL;
Procedure Button5_CTRL;
Procedure PrevSong;
// always goes to the previous song (unlike button 1), 1.666+
Procedure PopUpLoadFile;
// pops up the load file(s) box
Procedure PopUpPreferences;
// pops up the preferences
Procedure AlwaysOnTop;
// toggles always on top
Procedure PopUpAboutBox;
// pops up the about box
Procedure Terminate;
// closes winamp (added Aug 31 1998)
implementation
Var hWnd_WinAmp : hWnd;
Procedure GethWnd_WinAmp;
begin
hwnd_winamp := FindWindow('Winamp v1.x', nil);
end;
Procedure GetVersion;
begin
{
IPC_GETVERSION is sent to the window, and the return value is the version
Version 1.55 = 0x1551
Version 1.6b = 0x16A0
Version 1.60 = 0x16AF
Version 1.61 = 0x16B0
Version 1.62 = 0x16B1
Version 1.64 = 0x16B3
Version 1.666 = 0x16B4
Version 1.69 = 0x16B5
Version 1.70 = 0x1700
Version 1.72 = 0x1702
Version 1.72 = 0x1703
the command_data parameter is 0.
so,
if (SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETVERSION) != 0x1551)
MessageBox(NULL,"Error, Winamp 1.55 not found","Warning",MB_OK);
}end;
procedure AddMp3ToPlayList(mp3ToAdd:string);
Var
x : integer;
begin
Mp3ToAdd:=MP3ToAdd+#0;
GethWnd_WinAmp;
for x:=0 to Length(MP3ToAdd) do
PostMessage(hwnd_winamp,wm_user,ord(mp3toadd[x]),IPC_PLAYFILE);
PostMessage(hwnd_winamp,wm_user,0,IPC_PLAYFILE);
end;
Procedure DeletePlayList;
begin
GethWnd_WinAmp;
SendMessage(hwnd_winamp,WM_USER,0,IPC_DELETE);
end;
Procedure StartPlay;
begin
GethWnd_WinAmp;
SendMessage(hwnd_winamp,WM_USER,0,IPC_STARTPLAY);
end;
Procedure ChangeDir(DirToChangeTo:string);
Var
x : integer;
begin
DirToChangeTo:=DirToChangeTo+#0;
GethWnd_WinAmp;
for x:=0 to Length(DirToChangeTo) do
PostMessage(hwnd_winamp,wm_user,ord(DirToChangeTo[x]),IPC_CHDIR);
PostMessage(hwnd_winamp,wm_user,0,IPC_CHDIR);
end;
Function PlayBackStatus : integer;
{ IPC_ISPLAYING returns the status of playback.
If it returns 1, it is playing. if it returns 3, it is paused, if it returns 0, it is not playing.
If it returns something other than 1,3,or 0, something is screwed.
}
begin
GethWnd_WinAmp;
PlayBackStatus:= SendMessage(hwnd_winamp,WM_USER,0,IPC_ISPLAYING);
end;
Function GetOutPutTime( x : integer): Integer;
{ IPC_GETOUTPUTTIME returns the position in milliseconds of the
current song (lParam = 0), or the song length, in seconds (lParam = 1).
Returns -1 if not playing or error.}
begin
GethWnd_WinAmp;
GetOutPutTime := SendMessage(hwnd_winamp,WM_USER,x,IPC_GETOUTPUTTIME);
end;
function JumpToTime(new_song_pos:integer):integer;
{ *ONLY AVAILABLE IN v1.60+*
IPC_JUMPTOTIME sets the position in milliseconds of the current song (approximately)
Returns -1 if not playing, 1 on eof, or 0 if successful }
begin
GethWnd_WinAmp;
JumpToTIme:=SendMessage(hwnd_winamp,WM_USER,new_song_pos,IPC_JUMPTOTIME);
end;
Function WritePlaylist : Integer;
{ *ONLY AVAILABLE IN v1.666+*
IPC_WRITEPLAYLIST writes the current playlist to <winampdir>//Winamp.pl }
begin
GethWnd_WinAmp;
WritePlayList := SendMessage(hwnd_winamp,WM_USER,0,IPC_WRITEPLAYLIST);
{ (cursong is the index of the current song in the playlist) }
end;
// THESE MIGHT CHANGE in the future
//Also, you can send standard WM_COMMAND messages to the Winamp window (for other controls), including
// Send using SendMessage(hwnd_winamp,WM_COMMAND,WINAMP_OPTIONS_EQ/*orwhatever*/,0);
Procedure ExecuteMessage(MessageToExecute:integer);
begin
GethWnd_WinAmp;
SendMessage(hwnd_winamp,WM_COMMAND,MessageToExecute,0);
end;
Procedure EQ;
// toggles the EQ window
begin
ExecuteMessage(WINAMP_OPTIONS_EQ);
end;
Procedure PlayList;
// toggles the playlist window
begin
ExecuteMessage(WINAMP_OPTIONS_PLEDIT);
end;
Procedure VolumeUp;
// turns the volume up a little
begin
ExecuteMessage(WINAMP_VOLUMEUP);
end;
Procedure VolumeDown;
// turns the volume do
wn a little
begin
ExecuteMessage(WINAMP_VOLUMEDOWN);
end;
Procedure Forward5;
// fast forwards 5 seconds
begin
ExecuteMessage(WINAMP_FFWD5S);
end;
Procedure Rewind5;
// rewinds 5 seconds
begin
ExecuteMessage(WINAMP_REW5S);
end;
// the following are the five main control buttons, with optionally shift or control pressed
// (for the exact functions of each, just try it out)
Procedure Button1;
begin
ExecuteMessage(WINAMP_BUTTON1);
end;
Procedure Button2;
begin
ExecuteMessage(WINAMP_BUTTON2);
end;
Procedure Button3;
begin
ExecuteMessage(WINAMP_BUTTON3);
end;
Procedure Button4;
begin
ExecuteMessage(WINAMP_BUTTON4);
end;
Procedure Button5;
begin
ExecuteMessage(WINAMP_BUTTON5);
end;
Procedure Button1_Shift;
begin
ExecuteMessage(WINAMP_BUTTON1_SHIFT);
end;
Procedure Button2_Shift;
begin
ExecuteMessage(WINAMP_BUTTON2_SHIFT);
end;
Procedure Button3_Shift;
begin
ExecuteMessage(WINAMP_BUTTON3_SHIFT);
end;
Procedure Button4_Shift;
begin
ExecuteMessage(WINAMP_BUTTON4_SHIFT);
end;
Procedure Button5_Shift;
begin
ExecuteMessage(WINAMP_BUTTON5_SHIFT);
end;
Procedure Button1_CTRL;
begin
ExecuteMessage(WINAMP_BUTTON1_CTRL);
end;
Procedure Button2_CTRL;
begin
ExecuteMessage(WINAMP_BUTTON2_CTRL);
end;
Procedure Button3_CTRL;
begin
ExecuteMessage(WINAMP_BUTTON3_CTRL);
end;
Procedure Button4_CTRL;
begin
ExecuteMessage(WINAMP_BUTTON4_CTRL);
end;
Procedure Button5_CTRL;
begin
ExecuteMessage(WINAMP_BUTTON5_CTRL);
end;
Procedure PrevSong;
begin
ExecuteMessage(WINAMP_PREVSONG);
// always goes to the previous song (unlike button 1), 1.666+
end;
Procedure PopUpLoadFile;
// pops up the load file(s) box
begin
ExecuteMessage(WINAMP_FILE_PLAY);
end;
Procedure PopUpPreferences;
// pops up the preferences
begin
ExecuteMessage(WINAMP_OPTIONS_PREFS);
end;
Procedure AlwaysOnTop;
// toggles always on top
begin
ExecuteMessage(WINAMP_OPTIONS_AOT);
end;
Procedure PopUpAboutBox;
// pops up the about box
begin
ExecuteMessage(WINAMP_HELP_ABOUT);
end;
Procedure Terminate;
begin
GetHWnd_WinAmp;
SendMessage(HWnd_WinAmp, WM_DESTROY, 0,0);
// closes WinAmp
end;
end.