Delphi -- 从剪贴板拷贝文件示例代码

uses Windows, Clipbrd, ShellAPI ....;

var
  DropHandle, DropEffect, Effect : HDROP;
  FileCount:Integer;
  Counter:Integer;
  FileName:array [0..MAX_PATH] of char;
const
  DROPEFFECT_NONE   = 0;
  DROPEFFECT_COPY   = 1;
  DROPEFFECT_MOVE   = 2;
  DROPEFFECT_LINK   = 4;
  DROPEFFECT_SCROLL = $80000000;
begin
  OpenClipboard(0);
  DropEffect := RegisterClipboardFormat('Preferred DropEffect');
  DropHandle := GetClipboardData(CF_HDROP);
  if DropHandle>0 then
  begin
    Effect := GetClipboardData(DropEffect);
    if Effect=0 then Effect := DROPEFFECT_COPY
    else Effect := PDWORD(Effect)^;
    case Effect of
      DROPEFFECT_COPY + DROPEFFECT_LINK:ShowMessage('Copy');
      DROPEFFECT_MOVE:ShowMessage('Move');
    end;
    FileCount:=DragQueryFile(DropHandle,Cardinal(-1),nil,0);
    for Counter := 0 to FileCount-1 do
    begin
      DragQueryFile(DropHandle, Counter, FileName, sizeof(FileName));
      ShowMessage(FileName);
    end;
  end;
  CloseClipboard;
end;

posted @ 2011-03-09 23:57  Max Woods  阅读(789)  评论(0编辑  收藏  举报