德尔福 - 拖放放大器;与ListView控件拖放 [英] Delphi - Drag & Drop with ListView
问题描述
晚上好: - )
我有这样的code到使用拖放放大器;跌落对于文件的方法
I have this code to use Drag & Drop method for files:
TForm1 = class(TForm)
...
public
procedure DropFiles(var msg: TMessage ); message WM_DROPFILES;
end;
procedure TForm1.FormCreate(Sender: TObject)
begin
DragAcceptFiles(ListView1.Handle, True);
end;
procedure TForm1.DropFiles(var msg: TMessage );
var
i, count : integer;
dropFileName : array [0..511] of Char;
MAXFILENAME: integer;
begin
MAXFILENAME := 511;
count := DragQueryFile(msg.WParam, $FFFFFFFF, dropFileName, MAXFILENAME);
for i := 0 to count - 1 do
begin
DragQueryFile(msg.WParam, i, dropFileName, MAXFILENAME);
Memo1.Lines.Add(dropFileName);
end;
DragFinish(msg.WParam);
end;
在的ListView 为 DragCursor ,但在Memo1的不是任何记录的区域。
当我使用例如的ListBox 和方法的 DragAcceptFiles(ListBox1.Handle,真)的永远是好的。
In area of ListView is DragCursor, but in Memo1 aren't any records. When I use for example ListBox and method DragAcceptFiles(ListBox1.Handle, True) ever is fine.
的ListView 属性的 DRAGMODE 我设置为 dmAutomatic
感谢: - )
推荐答案
您已经呼吁为ListView DragAcceptFiles,因此Windows发送WM_DROPFILES到你的ListView,而不是你的表格。你必须赶上从ListView中WM_DROPFILES消息。
You've called DragAcceptFiles for the ListView, so Windows sends the WM_DROPFILES to your ListView and not to your Form. You have to catch the WM_DROPFILES message from the ListView.
private
FOrgListViewWndProc: TWndMethod;
procedure ListViewWndProc(var Msg: TMessage);
// ...
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// Redirect the ListView's WindowProc to ListViewWndProc
FOrgListViewWndProc := ListView1.WindowProc;
ListView1.WindowProc := ListViewWndProc;
DragAcceptFiles(ListView1.Handle, True);
end;
procedure TForm1.ListViewWndProc(var Msg: TMessage);
begin
// Catch the WM_DROPFILES message, and call the original ListView WindowProc
// for all other messages.
case Msg.Msg of
WM_DROPFILES:
DropFiles(Msg);
else
if Assigned(FOrgListViewWndProc) then
FOrgListViewWndProc(Msg);
end;
end;
这篇关于德尔福 - 拖放放大器;与ListView控件拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!