Learning to use resource files [2]-ico

Source: Internet
Author: User
Now I want to create a resource file with two icons and call it.

1. Create a new project and save it. Note that {$ R *. Res} will not be deleted this time}

2. Copy two ICO files to the project directory, for example, icofile_1.ico and icofile_2.ico.

3. Create a text file input:
Ico1 icon icofile_1.ico
Ico2 icon icofile_2.ico

Save it as Myres. RC and add it to the project ,:

4. At this time, the project file will be automatically inserted: {$ R 'myres. res '}

5. Add four buttons to implementCodeAs follows:

Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure submit (Sender: tobject ); end; var form1: tform1; implementation {$ R *. DFM} // use the first custom icon in the resource procedure tform1.button1click (Sender: tobject); begin application. icon. handle: = loadicon (hinstance, 'ico1'); {hinstance current Program Instance handle, which must be used to call a resource file; ico1 is the resource file identifier; loadicon is an API function used to call the ICO file in the resource, it returns the handle of the specified ICO file .} end; // use the second custom icon procedure tform1.button2click (Sender: tobject) in the resource; begin application. icon. handle: = loadicon (hinstance, 'ico2 '); end; // use the default program icon procedure tform1.button3click (Sender: tobject) in the resource; begin application. icon. handle: = loadicon (hinstance, 'mainicon '); end; // do not use the icon (the default icon for Windows is displayed) Procedure tform1.button4click (Sender: tobject); begin application. icon: = nil; end.
  
   
 //:


Note:

1. Myres. RC is compiled into Myres. Res;

2. The icofile_1.ico and icofile_2.ico files are compiled into Myres. Res;

3. The Myres. Res file is also compiled into project1.exe.

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.