Display the Windows icon in Delphi

Source: Internet
Author: User

The column contains an article, "Delphi controls for extracting icons," which can be used to extract the icons contained in the file, but not the default icons for files that do not contain icons in the same way as Windows Explorer. This article describes the method of displaying this icon in the ListView widget of Delphi, combined with the "Delphi Control for extracting icons" article to show almost all the icons. A major feature of this approach is the ability to display many Windows icons without drawing any icons.

Original from: "100 script net Www.pc100.net"

---- A large number of icon display is a major feature of Windows, colorful icons not only beautify the Windows desktop, but also easy to intuitive operation, to bring great convenience to users. It can be said that in a way, the status of the icon has exceeded the role of the file name.

---- However, when we use visual programming tools for Windows programming, there are few convenient ways to load and display icons. In general, when we use the icon resource in our application, we draw it ourselves. Therefore, the icons used in our programmed programs are very limited. We know that there are a number of known system icons in Windows, such as icons for folders, icons for disk drives, and so on. Friends who are familiar with Windows programming may know that these icons have a specific number inside windows, and that they can call and display the corresponding icons as soon as they get the numbers. By comparison, I chose the ListView component in Delphi to display the icon, because this method is the simplest.

---- Below is an example of the program that was compiled in Delphi 4.0.

---- The demo program can display a variety of Windows system icons, including file icon, disk icon, folder icon, user-specific executable icon (such as: Delphi torch icon, etc.). Interestingly, none of these icons we have shown need to be drawn by ourselves manually.

---- first set up a form Form1 in the Delphi environment, and add a button Button1 and a list box ListView1 in Form1, and then set the ListView1 property Viewstyle to Vsicon.

---- source program manifest:

Unit unit1;interfaceuses Windows, Messages, Sysutils, Classes, Graphics, Controls, Forms, Dialogs, Comctrls, Stdctrls, S    Hellapi, extctrls, Imglist;type TForm1 = Class (Tform) Listview1:tlistview;    Button1:tbutton;    Procedure Formdestroy (Sender:tobject);    Procedure Formcreate (Sender:tobject);  Procedure Button1Click (Sender:tobject);  Private {Private declarations} public {public declarations} end;const test= ' c:/'; {Test is the testing data, in this case a drive icon is returned. Readers can choose their own other test data such as: test:= ' C:/autoexec.bat ' and so on.  }var Form1:tform1; shfileinfo:tshfileinfo;implementation{$R *.  Dfm}function Getfileiconindex (filename:string): integer;  {Gets the ordinal function of the icon}var Ext:string;begin ext:=filename; Result:=shgetfileinfo (Pchar (EXT), 0, Shfileinfo, SizeOf (shfileinfo), Shgfi_largeicon or Shgfi_sysiconinde  X or Shgfi_typename);   Result:=shfileinfo.iicon; {Returns the obtained icon ordinal}end;procedure tform1.formcreate (sender:tobject); begin with ListView1 do begin Smallimages:=timageli St.      Createsize (32,32);      Smallimages.shareimages:=true; Smallimages.handle:=shgetfileinfo (' *. * ', 0,shfileinfo, SizeOf (shfileinfo), Shgfi_largeicon Orshgfi_icon or SHGFI_      Sysiconindex);      Largeimages:=timagelist.createsize (32,32);      Largeimages.shareimages:=true; Largeimages.handle:=shgetfileinfo (' *. * ', 0,shfileinfo, SizeOf (shfileinfo), Shgfi_largeicon Orshgfi_icon or SHGFI_    Sysiconindex); End  {Assign system resources to LISTVIEW1 components to display icons}end;procedure Tform1.formdestroy (sender:tobject); begin ListView1.SmallImages.Free;  ListView1.LargeImages.Free; {Release ListView1 of system resources}end;procedure Tform1.button1click (sender:tobject); begin listview1.items.item[0].  Imageindex:=getfileiconindex (Test); {The icon}end;end is drawn for the first item in ListView1.}
http://www.zhihu.com/question/23952865http://www.zhihu.com/question/22481342http://www.iqiyi.com/u/ 1110574148http://wenku.baidu.com/view/d159f2455a8102d276a22fb0http://www.docin.com/p1-1076470440.htmlhttp:// f.dataguru.cn/thread-482973-1-1.htmlhttp://www.yangtai.com/bbs/321319http://www.sharejs.com/codes/javascript/ 9063http://www.sharejs.com/codes/php/9062http://www.360doc.com/myfiles.aspx?app=1&type=3

Display the Windows icon in Delphi

Related Article

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.