2015年11月2日 星期一

delphi 把檔案拖到已經在執行中的程式???

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, $FFFFFFFF, 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));

     // 這裡的 S 是完整的檔名(含路徑), 就在這裡做執行的動作
    end;
    { DragFinish completes the operation and frees the associated resources. }
    DragFinish(Drop);
  end;
end;

沒有留言: