Winapi: extracticon-Get icons in EXE, DLL, or ICO files

Source: Internet
Author: User
// Declaration: extracticon (hinst: hinst; {call the function's Program Instance} lpszexefilename: pchar; {file path; file may 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}
  
   
 // Example: 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 = clientwidth-W then begin X: = 10; Y: = Y + H + 10; end; end; ICO. free; end.
 
   
 //:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.