unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
procedure ExtractFromLNK(FileName: String);
procedure WMDROPFILES (var Msg: TMessage); message WM_DROPFILES;
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
ShellAPI; // API함수 사용을 위해 반드시 포함
//
// 바로가기에서 아이콘을 뽑아 TImage에 뿌리는 함수
//
procedure TForm1.ExtractFromLNK(FileName: String);
var
Icons: PWORD;
ico: TIcon;
hic: HIcon;
begin
GetMem(Icons, sizeof(word));
Icons^ := 0;
ico := TIcon.Create;
hic := ExtractAssociatedIcon(Hinstance, PChar(FileName), Icons^);
try
ico.handle := hic;
DrawIcon(ico.handle, 0, 0, hic);
if not (ico.Empty) then
Image1.Picture.Icon := ico;
finally
FreeMem(Icons, sizeof(word));
ico.free;
end;
end;
//
// 파일이 드롭되었을 때 처리하는 함수
//
procedure TForm1.WMDROPFILES(var Msg: TMessage);
var
i: Integer;
Amount: Integer;
Size: Integer;
Filename: PChar;
S: String;
begin
inherited;
Amount := DragQueryFile(Msg.WParam, $FFFFFFFF, Filename, 255);
for i := 0 to (Amount-1) do
begin
size := DragQueryFile(Msg.WParam, i , nil, 0) + 1;
Filename:= StrAlloc(size);
DragQueryFile(Msg.WParam,i , Filename, size);
s := ExtractFileExt(FileName);
if s = '.lnk' then
begin
ExtractFromLNK(FileName);
end;
StrDispose(Filename);
end;
DragFinish(Msg.WParam);
end;
//
// 드롭 메세지를 받을 수 있도록...
//
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(Form1.Handle, True));
end;
end.
곽성주 님이 쓰신 글 :
:
:
: 그림파일 아이콘을 드래그하여 이미지콘트롤 위에 놓으면 그림이 보여지게 하고 싶습니다. 어찌해야 하나요?
:
: 아이콘은 바탕화면에서 긁어올것입니다.
:
: 고수님들의 조언 바랍니다~
|