ExtractIcon (hInst: HINST; {program instance that calls the function} lpszExeFileName: PChar; {file path; file can be *. exe ,*. dll ,*. ico} nIconIndex: UINT {icon index}): HICON; {return icon handle; returns the first icon handle when the index is 0; returns the total number of icons when the index is # FFFFFFFF}
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, extctrls; Type tform1 = Class (tform) button1: tbutton; procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses shellapi; {extracticon declares in it} procedure tform1.button1click (Sender: tobject); var ICO: ticon; I, Count, X, Y, W, H: integer; filepath: string; begin {any path is found. If it is missing, it will exit.} filepath: = 'C: \ Program Files \ Macromedia \ fireworks 8 \ fireworks.exe '; if not fileexists (filepath) then begin showmessage ('file does not exist'); exit; end; ICO: = ticon. create; X: = 10; Y: = 10; W: = 0; H: = 0; repaint; {calculate the total number of icons in the file first} count: = extracticon (hinstance, pchar (filepath), hicon (-1); for I: = 0 to count-1 do begin {loop extraction icon} ico. handle: = extracticon (hinstance, pchar (filepath), I); {draw icon} canvas. draw (X, Y, ico); {The following is just to adjust the display position} If W <ICO. width then W: = ICO. width; If H <ICO. height then h: = ICO. height; X: = x + ICO. width + 10; if x> = clientwidth-W then begin X: = 10; Y: = Y + H + 10; end; ICO. free; end.