//uses ShellAPI
procedure TForm1.Button1Click(Sender: TObject);
var
IconIndex:Word;
h:hICON;
begin
IconIndex:=0;
h:=ExtractIcon(HInstance,pchar('c:"windows"notepad.exe'),IconIndex);
DrawICon(Form1.canvas.Handle,200,100,h);
end;
//用控件ImageList保存提取的图标,并在ListView中显示出来
FIcon.Handle:=hIcon1;
ImageList1.AddIcon(fIcon);
ListItem:=ListView1.Items.Add;
ListItem.ImageIndex:=ImageList1.Count-1;
end;
====================================================
use shellapi; //提取出图标并赋给SpeedButton.Glyph
procedure TForm1.Button1Click(Sender: TObject);
var
hc: TIcon;
Bitmap : TBitmap;
begin
//打开exe
opendialog1.Execute;
hc := TIcon.Create;
Bitmap := TBitmap.Create;
//提取exe图标
hc.Handle := ExtractIcon(hInstance, PChar(opendialog1.FileName), 0);
//将得到的ico转换为bitmap
Bitmap.Width := hc.Width;
Bitmap.Height := hc.Height;
Bitmap.Canvas.Draw(0, 0, hc );
//把bitmap传给speedbutton.glyph
SpeedButton1.Glyph:=bitmap;
//释放资源
hc.Free;
Bitmap.Free;
end;
|
请发表评论