function GetFileName( fname : String ) : String;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.AcceptFiles(var Msg: TWMDropFiles);
const
cnMaxFileNameLen = 255;
var
i, nCount : integer;
acFileName : array [0..cnMaxFileNameLen] of char;
LItem : TListItem;
shFI: TSHFILEINFO;
begin
// find out how many files we're accepting
//nCount := DragQueryFile(msg.WParam, $FFFFFFFF, acFileName, cnMaxFileNameLen);
nCount := DragQueryFile(msg.Drop, $FFFFFFFF, acFileName, cnMaxFileNameLen);
// query Windows one at a time for the file name
for i := 0 to nCount-1 do begin
//DragQueryFile(msg.WParam, i, acFileName, cnMaxFileNameLen);
DragQueryFile(msg.Drop, i, acFileName, cnMaxFileNameLen);
애구 여기저기 뒤지다 우연히 했어요....
<!--CodeS-->
unit d_i;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ShellAPI, ComCtrls, ImgList, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListView1: TListView;
il: TImageList;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure AcceptFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
function GetFileName( fname : String ) : String;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.AcceptFiles(var Msg: TWMDropFiles);
const
cnMaxFileNameLen = 255;
var
i, nCount : integer;
acFileName : array [0..cnMaxFileNameLen] of char;
LItem : TListItem;
shFI: TSHFILEINFO;
begin
// find out how many files we're accepting
//nCount := DragQueryFile(msg.WParam, $FFFFFFFF, acFileName, cnMaxFileNameLen);
nCount := DragQueryFile(msg.Drop, $FFFFFFFF, acFileName, cnMaxFileNameLen);
// query Windows one at a time for the file name
for i := 0 to nCount-1 do begin
//DragQueryFile(msg.WParam, i, acFileName, cnMaxFileNameLen);
DragQueryFile(msg.Drop, i, acFileName, cnMaxFileNameLen);
//파일명 MessageBox로 보여줌
//MessageBox(Handle, acFileName, '', MB_OK);
LItem := ListView1.Items.Add;
LItem.Caption := GetFileName( acFileName );
//LItem.ImageIndex := 0;
SHGetFileInfo(acFileName,0, shFI,sizeof(SHFILEINFO),
SHGFI_ICON or SHGFI_LARGEICON or SHGFI_SYSiconINDEX or SHGFI_TYPENAME);
LItem.ImageIndex := shFI.iicon;
end;
// let Windows know that you're done
DragFinish(msg.Drop);
end;
function TForm1.GetFileName( fname : String ) : String;
var
i : Integer;
tmp : String;
begin
tmp := '';
for i := Length( fname ) downto 1 do begin
if fname[i] = '\' then Break;
tmp := fname[i] + tmp;
end;
Result := tmp;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
SHFileInfo : TSHFILEINFO;
begin
DragAcceptFiles(Handle, True);
il.handle := ShGetFileInfo('',0,ShFileInfo,SizeOf(ShFileInfo), SHGFI_LARGEICON or SHGFI_ICON or SHGFI_SYSiconINDEX);
end;
end.
<!--CodeE-->