Delphi - Drag & Drop with ListView

后端 未结 2 1044
情深已故
情深已故 2021-01-03 08:59

Good evening :-)!

I have this code to use Drag & Drop method for files:

TForm1 = class(TForm)
...
public
    pr         


        
相关标签:
2条回答
  • 2021-01-03 09:43

    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;
    
    0 讨论(0)
  • 2021-01-03 09:47

    Your problem is, you're registering the list view window as a drop target, but handling the WM_DROPFILES message in the form class. The message is sent to the list view control, you should handle the message there.

    0 讨论(0)
提交回复
热议问题