background image

 

begin

  

self.Image1.Canvas.Refresh;

  

nIcons:=ExtractIconEx(PChar(OpenDialog1.FileName), -1, Large, Small, 1);

  

for i:=0 to nIcons-1 do

  

begin

   

ExtractIconEx(PChar(self.OpenDialog1.FileName), i, Large, Small, 1);

   

DrawIcon(self.Image1.Canvas.Handle,(i div 4)*40,(i mod 4)*40,Large);

  

end;

 

end;

end;

    当 用 户 在 程 序 运 行 过 程 中 选 择 一 个 可 执 行 文 件 后 , 程 序 首 先 通 过

self.Image1.Canvas. Refresh 语句清除 TImage 组件上的显示内容,然后通过

ExtractIconEx 函数的第 2 个参数指定为-1 来取得可执行文件中图标的数目。得

ExtractIconEx 

(PChar(self.OpenDialog1.FileName), i, Large, Small, 1)语句把可执行文件中

的大、小图标分别存储在

Large 和 Small 变量中。最后通过 DrawIcon 函数在

TImage 组件上绘制图标。

  程序代码如下:

unit Unit1;

interface