Function Enumresname(hmodule:Hmodule;lptype,lpname:Pchar;                    lparam:longint):Bool;stdcall;
var hicon1:hicon;
hresource:hrsrc;
hmem:hrsrc;
lpresource:pbyte;
listitem:Tlistitem;
begin
 hresource:=findresource(hexe,lpname,RT_ICON);
 hmem:=loadresource(hexe,hresource);
 lpresource:=lockresource(hmem);//返回指向锁定资源头字节的指针
 hicon1:=Createiconfromresourceex(lpresource,sizeofresource(hexe,hresource),
 True,$0030000,32,32,LR_DEFAULTCOLOR);//从锁定可执行资源创建图标句柄
 With Form1 do
 begin //显示处理
 Ficon.handle:=hicon1;
 imagelist1.addicon(ficon);
 listitem:=listview1.items.add;
 ListItem.ImageIndex := imagelist1.count - 1;
 ListItem.caption:= format('图标%d',[imagelist1.count]);
 end;
 result:=True;
end;文中主要是对.exet和.dll文件中的图标取出来.但是前面几句话看也看不懂,更不知道是怎么个原理取出来的.如果要对其取出的图标进行存储,又该如何写呢?请帮忙把内容具体地解释一下.

解决方案 »

  1.   

    看findresource,loadresource,lockresource,Createiconfromresourceex这几个函数的F1,如果是作者自己写的就....
      

  2.   

    findresource,loadresource,lockresource,Createiconfromresourceex
    上面這幾個都是API函數來的,
    findresource是在一個指定的句柄中查詢一個查詢的資源,本例中為ICO,即圖標資料
    關於以上函數的詳細說明,樓主可以看API幫助如果樓主要保存的話,可以直接調用Ficon.SaveToFile
    如果要保存imagelist1中所有的圖標,可以調用GetIcon,然後再用Icon的SavetoFile的方法
      

  3.   

    写了保存的一段:出现错误(icon image is not valid)
    procedure TForm1.Save1Click(Sender: TObject);
    var
      i: integer;
      SavePath: string;
    begin
      if Imagelist1.Count=0 then
      begin
        Application.MessageBox('请解出图标!',
                               '消息框',
                                MB_OK + MB_DEFBUTTON1 + MB_ICONINFORMATION);
        Exit;
      end;
      SelectDirectory('请选择保存路径:','我的电脑',SavePath);
      if SavePath <> '' then
      begin
        if SavePath[Length(SavePath)] = '\' then
          SavePath := Copy(SavePath,1,Length(SavePath)-1);
        fIcon := TIcon.Create;
        for i := 0 to Imagelist1.Count - 1 do
          begin
          imagelist1.GetIcon(i,icon);
          fIcon.SaveToFile(SavePath + '\' + IntToStr(i + 1) + '.ico');(到此出错:icon image is not valid)
          fIcon.ReleaseHandle;
          end;
        fIcon.Free;
      end;
    end;
    帮忙一下,好结帖了.