Delphi实现文件拖拽

在uses里引用ShellAPI单元;

在Form的OnCreate事件里添加以下语句:

DragAcceptFiles(Self.Handle, True); 

这里Self.Handle可以换成其它控件的句柄,如Self.Memo1.Handle;

然后编写文件拖拽功能要实现的目的:

procedure DragDropFiles(var msg : TWMDropFiles);  // 文件拖拽
message WM_DROPFILES;

下面是事件实现的关键代码:

FileName : array [0..255] of Char;
i, iCount   : Integer;
iCount := DragQueryFile(msg.Drop, $FFFFFFFF, nil, 0);    // 文件数量
DragQueryFile(msg.Drop, i - 1, @FileName, SizeOf(FileName));
DragFinish(msg.Drop);

猜你喜欢

转载自blog.csdn.net/u012366767/article/details/81633872