怎样实现音乐文件的拖放播放?(50分)

  • 主题发起人 主题发起人 honghu
  • 开始时间 开始时间
H

honghu

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样实现音乐文件的拖放播放?
我用trackbar的onchange事件不行呀!
请教!!!!!!!![:(][green][/green]
 
给你看段关于如何拖拉的代码吧,至于拿到文件后如何播放你自己去做吧。

unit Unit1;


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;


type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
procedure FormCreate(Sender: TObject);

procedure FormDestroy(Sender: TObject);

private
{ Private declarations }
procedure WMDROPFILES(var Msg: TMessage);

procedure LBWindowProc(var Message: TMessage);

procedure AddFile(sFileName: string);

public
{ Public declarations }
end;



var
Form1: TForm1;


implementation

{$R *.DFM}

uses
ShellAPI;


var
OldLBWindowProc: TWndMethod;


procedure TForm1.AddFile(sFileName: string);

begin

ListBox1.Items.Add(sFilename);

end;



procedure TForm1.FormCreate(Sender: TObject);

begin

OldLBWindowProc := ListBox1.WindowProc;
// store defualt WindowProc
ListBox1.WindowProc := LBWindowProc;
// replace default WindowProc
DragAcceptFiles(ListBox1.Handle, True);
// now ListBox1 accept dropped files
end;



procedure TForm1.FormDestroy(Sender: TObject);

begin

ListBox1.WindowProc := OldLBWindowProc;

DragAcceptFiles(ListBox1.Handle, False);

end;



procedure TForm1.LBWindowProc(var Message: TMessage);

begin

if Message.Msg = WM_DROPFILES then

WMDROPFILES(Message);
// handle WM_DROPFILES message
OldLBWindowProc(Message);

// call default ListBox1 WindowProc method to handle all other messages
end;



procedure TForm1.WMDROPFILES(var Msg: TMessage);

var
pcFileName: PChar;

i, iSize, iFileCount: integer;

begin

pcFileName := '';
// to avoid compiler warning message
iFileCount := DragQueryFile(Msg.wParam, $FFFFFFFF, pcFileName, 255);

for i := 0 to iFileCount - 1do

begin

iSize := DragQueryFile(Msg.wParam, 0, nil, 0) + 1;

pcFileName := StrAlloc(iSize);

DragQueryFile(Msg.wParam, i, pcFileName, iSize);

if FileExists(pcFileName) then

AddFile(pcFileName);
// method to add each file
StrDispose(pcFileName);

end;


DragFinish(Msg.wParam);

end;



end.


 
兄弟,你弄错啦!不是拖拽文件,而是播放进度条的拖拉!不好意思我没有表达清楚[:D][purple][/purple]
 
你可以用trackbar的onmousedown和onmouseup事件啊不过要说明一下,这两个事件要自已添加的啊, 我就用这个做了个Flash播放器没有什么不便
关于加事件:
TMyTrackBar = class(TTrackBar)
published
property OnMouseDown;
end;


 
多人接受答案了。
 
后退
顶部