在Windows的檔案總管中,如何完成檔案操作的呢? |
答題得分者是:hagar
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
報告 10 星上將, 參考以下兩篇, 也許有您要的:
1.Drag and drop from explorer
http://www.howtodothings.com/showarticle.asp?article=17
unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } protected procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} uses ShellAPI; procedure TForm1.FormCreate(Sender: TObject); begin { This call to DragAcceptFiles tells Windows that we want to know when files are dropped on our form from Explorer or File Manager. } DragAcceptFiles(Handle, TRUE); end; procedure TForm1.FormDestroy(Sender: TObject); begin { Notify Windows that we no longer want drop notification messages. } DragAcceptFiles(Handle, FALSE); end; procedure TForm1.WMDropFiles(var Msg: TWMDropFiles); var I: integer; S: string; begin with Msg do begin { Calling DragQueryFile with the file number as -1 ($FFFFFFFF) will return the number of files which were dropped on the form. } for I := 0 to DragQueryFile(Drop, -1, nil, 0) - 1 do begin { Here we call DragQueryFile for each file dropped specifying a buffer length of zero the determine the number of characters needed for the filename, and then use SetLength to allocate the proper amount of space. Note that we must add one to the value returned by DragQueryFile to leave room for the null-terminator. } SetLength(S, DragQueryFile(Drop, I, nil, 0) 1); { Get the complete filename in S. Any processing which needs to be done for each file can be done after this call. } DragQueryFile(Drop, I, PChar(S), Length(S)); end; { DragFinish completes the operation and frees the associated resources. } DragFinish(Drop); end; end; end.2.How to paste files from Windows Explorer into your application http://www.lmc-mediaagentur.de/dpool/tips/0657.htm uses clipbrd, shellapi; {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var f: THandle; buffer: Array [0..MAX_PATH] of Char; i, numFiles: Integer; begin Clipboard.Open; try f := Clipboard.GetAsHandle( CF_HDROP ); if f <> 0 then begin numFiles := DragQueryFile( f, $FFFFFFFF, nil, 0 ); memo1.Clear; for i:= 0 to numfiles - 1 do begin buffer[0] := #0; DragQueryFile( f, i, buffer, sizeof(buffer)); memo1.lines.add( buffer ); end; end; finally Clipboard.close; end; end;--- 歡迎光臨 KTop 研究院 |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |