类似豪杰“选曲”的功能该怎样实现。具体地说就是我写了一个播放器,
当选择多个媒体文件时我想实现豪杰“选曲”一摸一样的功能。如果有
切实可用的例子(代码)再加100分。

解决方案 »

  1.   

    使用Dragacceptfiles 函数
    unit Unit1;interfaceuses
      Windows, Messages, shellapi,SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Memo1: TMemo;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        procedure WMDrops( var message:tmessage);message WM_DROPFILES;
    { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
     Dragacceptfiles(form1.handle,true);end;
    procedure TForm1.WMDrops(var message:tmessage);
    var
    p:array[0..254] of char;
    i:word;
    begin
    inherited;
    form1.Memo1.Clear;
    {$IFDEF WIN32}
    i:=DragQueryFile(Message.wParam,$ffffffff,nil,0);
    {$ELSE}
    i:=DragQueryFile(Message.wParam,$ffff,nil,0);
    {$ENDIF}
    caption:=inttostr(i);
    for i:=0 to i-1 do
    begin
    DragQueryFile(Message.wParam,i,p,255);
    form1.Memo1.Lines.Add(strpas(p));
    end;
    memo1.Lines.LoadFromFile(memo1.Lines[0]);
    end;end.
      

  2.   

    这个我做过,不过代码不在本机上,思路是这样的,首先把打开文件对话框中的所有TString用一个Listbox保存起来,然后动态菜单,在创建每个动态菜单的同时将它的click事件关联起来,
      菜单的选曲事件(Click事件)可以先写一个过程Procedure.
      

  3.   

    tylerchen(蓝鱼):一定要请您多多帮忙,代码管用再加一百,大家监督。
      

  4.   

    哈哈,动态菜单我已做好,但关联出现问题。当我点击菜单中的一首歌时,
    播放器马上播放最后一首歌。代码如下:
    nit Unit4;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, MPlayer, Menus,shellapi;type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        MediaPlayer1: TMediaPlayer;
        Timer1: TTimer;
        Button1: TButton;
        OpenDialog1: TOpenDialog;
        MainMenu1: TMainMenu;
        N1: TMenuItem;
        procedure Button1Click(Sender: TObject);
        procedure PlayAFile(num: integer);
        procedure Timer1Timer(Sender: TObject);
        procedure menuclick(sender: Tobject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;
      order: integer=0;
      k:     integer;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j: integer;
      menu: array[0..255] of Tmenuitem;
    begin
       if opendialog1.Execute then
          begin
             listbox1.Items:=opendialog1.Files;
             i:=listbox1.Items.Count;
             for j:=0 to i-1 do
               begin
                  menu[j]:=tmenuitem.Create(self);
                  menu[j].Caption:=listbox1.Items[j];              
                  menu[j].onClick:=menuclick;
                  k:=j;
                  MainMenu1.Items[0].Add(Menu[j]);
               end;
             playAFile(0);
          end;
    end;procedure TForm1.PlayAFile(num: integer);
    begin
      mediaplayer1.FileName:=listbox1.Items.Strings[num];
      mediaplayer1.Open;
      mediaplayer1.Play;
      timer1.Enabled := true;
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
      if mediaplayer1.Mode = mpStopped then
      begin
        if order < listbox1.Items.Count - 1 then
        begin
          Inc(order);
          PlayAFile(order);
        end;
      end;
    end;procedure  TForm1.menuclick(sender: Tobject);
    begin
       playAFile(k);
       order:=k;
    end;end.
       我虽然知道错在哪里,但我却不知怎样去改。请各位指教。
      

  5.   

    看不懂代码,原则上说,这不是高手问题。动态建立对象,事件响应,释放对象应该是中级水平的基本功哦。所以,学delphi到一定程度,个性的属性方法不重要,但必须把关键的类的属性和方法掌握。
    procedure  TForm1.menuclick(sender: Tobject);
    begin
       playAFile(k);
       order:=k;
    end;
    是共用的事件响应。delphi给了你唯一的参数,sender,学会根据它来响应才是正着,而你却用K,在这里违反OO思想。
      

  6.   

    to scripting(scripting)
    能否示范一下,偶比较菜,但偶也很想弄明白
      

  7.   

    tmenuitem(sender).caption就是曲名
    tmenuitem(sender).MenuIndex大概就是你的k
      

  8.   

    能不能用 sender 主个例子。非常感谢。