2011-03-22 74 views
2

晚上好:-)!德爾福 - 拖放ListView

我有這樣的代碼使用將&下降方法文件

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,但在備忘錄不是的任何記錄。 當我使用例如列表框和方法DragAcceptFiles(ListBox1.Handle,True)永遠是好的。

的ListView財產DRAGMODE我設置爲dmAutomatic

感謝:-)

+1

不起作用不是一個很好的描述你有任何問題。請詳細說明您的問題,並且不要忘記包含任何意外行爲的完整說明,看到的內容以及要查看的內容。如果涉及任何錯誤或異常,請包括錯誤消息和異常類名稱。 – jachguate 2011-03-22 20:24:42

+0

請**不要**發表重複的問題。 – 2011-03-22 20:29:09

+0

@jachguate:謝謝,DropFiles方法可能什麼都不做,但沒有任何錯誤。 – Nanik 2011-03-22 20:39:37

回答

6

您已經爲ListView調用DragAcceptFiles,所以Windows將WM_DROPFILES發送到您的ListView而不是您的窗體。您必須從ListView中捕獲WM_DROPFILES消息。

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

感謝您的決議:-)! – Nanik 2011-03-22 21:02:43

1

你的問題是,你要註冊列表視圖窗口下降的目標,但是處理的窗體類WM_DROPFILES消息。消息發送到列表視圖控件,您應該在那裏處理消息。

+0

謝謝,你能給我一個正確的語法嗎? – Nanik 2011-03-22 20:51:09