我是用覆盖appliction.onmessage 然后处理dragfile消息的方式做的,但是做到增加item这里不知道该怎么写了,并不是listview有caption subitem的属性,请问该咋整?
 
还有,如果直接写shelllistview onDragDropy应该也可以吧 ? 不知道要咋怎么做请指点我..

解决方案 »

  1.   

    直接用事件就可以了。
    你在listview的onDragDrop里要解释传过来的数据,然后给增加item
      

  2.   

    直接写shelllistview OnDragDrop不行
    你需要的是针对某个窗体允许外部Shell文件拖拽(DragAcceptFiles)
    然后针对该窗体处理WM_DROPFILES处理
      

  3.   

    额,不是很熟悉,前面想当然了,sorry。
    网上看了一些资料,然后动手做了一下,把基本的功能实现了。下面是代码,供楼主参考。
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      DragAcceptFiles(ShellListView1.Handle, true);
      Application.OnMessage := AppMessage;         
    end;procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
    var
      nFiles, I: Integer;
      Filename: string;
      newFileName:string;    
      point:TPoint;          //松开鼠标的位置
    begin
      // 判断是否是发送到ShellListView1的WM_DROPFILES消息
      if (Msg.message = WM_DROPFILES) and (msg.hwnd = ShellListView1.Handle) then
      begin
        { 取dropped files的数量 }
        nFiles := DragQueryFile (Msg.wParam, $FFFFFFFF, nil, 0);
        try
          for I := 0 to nFiles - 1 do  { 循环取每个拖下文件的全文件名}
          begin
            SetLength (Filename, 80);
            DragQueryFile (Msg.wParam, I, PChar (Filename), 80); {取文件名}
            DragQueryPoint(HDROP(Msg.wParam), point);            {取放开的位置}
            newFileName := GetPosPath(point)+'\'+ ExtractFileName(FileName);
            CopyFile(PChar(FileName), PChar(newFileName), true);
            ShellListView1.Refresh;
          end;
        finally
          DragFinish (Msg.wParam); {结束这次拖放操作}
        end;
        Handled := True;   {标识已处理了这条消息}
      end;
    end;{根据位置找到ShellListView1中的文件夹路径}
    function TForm1.GetPosPath(point:TPoint):string;
    var
      ListItem:TListItem;
    begin
      ListItem := ShellListView1.GetItemAt(point.X, point.Y);
      if ListItem<>nil then begin
        if ShellListView1.Folders[ListItem.Index].IsFolder then
          result := ShellListView1.Folders[ListItem.Index].PathName;
      end
      else
        result := ShellListView1.RootFolder.PathName;
    end;
      

  4.   

    忘记说了,上面是从外面拖文件到ShellListView中某一位置,实现复制文件到目的文件夹中这样一个效果。