출처 : 김영대님 홈피 (http://www.howto.pe.kr)

 

 

 

unit Main;

 

interface

 

uses
  Windows, Messages, SysUtils, Classes, ShellApi;

 

type
  TfrmMain=class(TForm)
      procedure FormActivate(Sender: TObject);
      procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    private
      procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;    
    end;
 

var
  frmMain: TfrmMain;

 

 

 

implementation

 

procedure TfrmMain.FormActivate(Sender: TObject);
begin
  // Drag&Drop Accept
  DragAcceptFiles(Handle, True);
end;

 

procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  // Drag&Drop Accept 해제
  DragAcceptFiles(Handle, False);
  // 폼닫기
  CanClose:=True;
end;

 

procedure TfrmMain.WMDropFiles(var Msg: TMessage);
var
  i, cntDropItem, DropItemNameLength: Integer;
  hDrop: THandle;
  DropItemPath: array [0..MAX_PATH] of Char;

begin
  try
    // Drop Handle
    hDrop:=Msg.wParam; 

    // Drop된 아이템 갯수
    cntDropItem:=DragQueryFile(hDrop, $FFFFFFFF, nil, 0);

    for i:=0 to cntDropItem-1 do begin
      // Drop된 파일경로 길이
      DropItemNameLength:=DragQueryFile(hDrop, i, nil, 0);
      // Drop된 파일경로
      DragQueryFile(hDrop, i, DropItemPath, DropItemNameLength+1);
      // 출력...
      OutputDebugString(PWideChar(DropItemPath));
    end;
  finally
    DragFinish(hDrop);
  end;
  Msg.Result:=0

  inherited;
end;










Posted by bloodguy
,