如何拖曳从shell中删除一个文件? [英] How can I drag & drop a file from the shell?

查看:106
本文介绍了如何拖曳从shell中删除一个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从桌面拖放一个视频文件(如.avi),但是ı不能把它带到我的程序。但是当我尝试在我的程序中拖放它工作正常。例如:我在我的专业版中有一个edittext和一个列表框,ı可以将edittext里面的文本移动到listbox。我不能得到什么区别?

I am trying to drag and drop a video file (like .avi) from desktop But ı can not take it to the my program.But when ı try to drag and drop inside my program it works fine.For ex: I have an edittext and a listbox inside my pro and ı can move text that inside edittext to listbox.I could not get what is the difference ??

我把视频使用openDialog.Butı想改变它拖放。

I take the video using openDialog.But ı wanna change it with drag and drop.

procedure TForm1.Button1Click(Sender: TObject);
   begin
     if OpenDialog1.Execute then
       begin
          MediaPlayer1.DeviceType:=dtAutoSelect;
          MediaPlayer1.FileName := OpenDialog1.FileName;
          Label1.Caption := ExtractFileExt(MediaPlayer1.FileName);
          MediaPlayer1.Open;
          MediaPlayer1.Display:=Self;
          MediaPlayer1.DisplayRect := Rect(panel1.Left,panel1.Top,panel1.Width,panel1.Height);
          panel1.Visible:=false;
          MediaPlayer1.Play;
       end;

   end;


推荐答案

这是一个简单的演示如何拖放文件从Windows资源管理器到ListBox(对于Delphi XE):

Here is a simple demo how to drag&drop files from Windows Explorer into a ListBox (for Delphi XE):

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  protected
    procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses ShellAPI;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DragAcceptFiles(Handle, True);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  DragAcceptFiles(Handle, False);
end;

procedure TForm1.WMDropFiles(var Msg: TMessage);
var
  hDrop: THandle;
  FileCount: Integer;
  NameLen: Integer;
  I: Integer;
  S: string;

begin
  hDrop:= Msg.wParam;
  FileCount:= DragQueryFile (hDrop , $FFFFFFFF, nil, 0);

  for I:= 0 to FileCount - 1 do begin
    NameLen:= DragQueryFile(hDrop, I, nil, 0) + 1;
    SetLength(S, NameLen);
    DragQueryFile(hDrop, I, Pointer(S), NameLen);

    Listbox1.Items.Add (S);
  end;

  DragFinish(hDrop);
end;

end.

这篇关于如何拖曳从shell中删除一个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆