控制WINAMP的问题!(50分)

  • 主题发起人 主题发起人 lxmzm
  • 开始时间 开始时间
L

lxmzm

Unregistered / Unconfirmed
GUEST, unregistred user!
hwndWinamp := FindWindow('Winamp v1.x', nil);
// close the exist Calculator
if hwndWinamp <> 0 then
begin
SendMessage(hwndWinamp, WM_CLOSE, 0, 0);
end;
hwndWinamp := FindWindow('Winamp v1.x', nil);
// close the exist Calculator
s := WinAmpDir() + 'winamp.exe';
WinExec(pchar(s), SW_SHOWNORMAL);
cds.dwData := 100;
/////define IPC_PLAYFILE 100
CDS.cbData := Length(filepath + filename) + 1;
;
cds.lpData := Pchar(filepath + filename);
SendMessage(hwndWinamp, WM_COPYDATA, 0, integer(@CDS));
但文件列表中,并没有出现预期的效果。
 
我的winamp是2.81版本的
 
不知你想干什么?也许写一个WinAmp插件更好些。
 
可能winexec这个命令是调用外部的exe文件,所以他执行完这句后就立刻执行下一语句,而
实际上winamp并还没有这么快执行,有时间差,你试试让系统sleep(5000)停5秒钟。
 
bu ming bai
 
这是N年前的代码了,不过,对目前的WINAMP也有一点用,我测试过,呵呵~
 
这个问题嘛,你可以问hubdog,他可是这方面的砖家,就不知道这混蛋还来不来大富翁。
我买了他的《delphi深度探险》结果好多看不懂,真想扁他一顿。
 
SendMessage(hwndWinamp, WM_COPYDATA,form1.handle, integer(@CDS));
////////////

WM_COPYDATA
The WM_COPYDATA message is sent when an application passes data to another application.
WM_COPYDATA
wParam = (WPARAM) (HWND) hwnd;
// handle of sending window
lParam = (LPARAM) (PCOPYDATASTRUCT) pcds;
// pointer to structure with data

Parameters
hwnd
Handle to the window passing the data.
pcds
Pointer to a COPYDATASTRUCT structure that contains the data to be passed.
Return Values
If the receiving application processes this message, it should return TRUE;
otherwise, it should return FALSE.
Remarks
An application must use theSendMessage function to send this message, not thePostMessage function.
The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data.
While this message is being sent, the referenced data must not be changed by another thread of the sending process.
The receiving application should consider the data read-only. The pcds parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by pcds. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.

 
引用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.
 
后退
顶部