Personalization Folder icon (Delphi)

zhaozj2021-02-16  48

Abandon Windows's default icon, let your program you are in the directory of Folder Icon! In fact, it is very simple. In fact, you only need a Desktop.ini file, and I will explain it from two aspects.

1. Manual way:

First, create a Desktop.ini file in a folder that needs to be changed, as follows [.shellclassInfo] confirmfileop = 0infotip = I own folder iconindex = 0ICONFILE = MyFolder.ico explanation: Parameters confirmfileop is set to 0 - Prevent users Warnings for "You are deleting system Directory" that pops up when you move or delete this folder. The parameter iconfile is specified as the location of the icon file to be changed, which can be an Icon, BMP, EXE, or DLL file. The icon file in the previous example is also placed in the same directory. The parameter iconIndex can specify the index of the file. If this icon file is an icon file, IconIndex is set to 0. Parameters Infotip is used to set the tooltip in this Folder in WINDOS.

The next step opens the CMD (Command Prompt), enter Attrib S i: / myfolderi: / myfolder refers to the path I want to change the icon directory. This operation is to make your folder become a system folder.

Ok, after manual processing, the current directory has changed.

2. Programming:

This way is to be implemented with the Delphi I like, and the same EASY is achieved. An establishment of the INI file, the other function is equivalent to Attrib S in the manual mode.

Unit unit1;

Interface

Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, INIFILES, STDCTRLS

TYPE TFORM1 = Class (TFORM) Button1: TButton; Procedure Button1Click (sender: TOBJECT); private {private declarations} end;

Var Form1: TFORM1;

IMPLEMENTATION

{$ R * .dfm}

Procedure TForm1.Button1Click (Sender: Tobject); var myinifile: tinifile; begin // The following steps are used to create Desktop.ini files // When there is an Ini file, you will create iNi myinifile: = tinifile.create (Application .Exename) 'Desktop.ini'); MyiniFile.WritString ('. Shellclassinfo', 'confirmfileop', '0'); MyiniFile.writestring ('. Shellclassinfo', 'Infotip', 'my folder thus change '); MyIniFile.WriteString (' ShellClassInfo ',' IconIndex ',' 0. '); MyIniFile.WriteString (' ShellClassInfo ',' IconFile ', ExtractFileName (Application.ExeName.)); MyIniFile.Free; // make file The clip is made into system folder setFileAttributes (PCHAR (Application.exename), getFileAttributes (Pchar (Application.exename)) or file_attribute_system; end; end.

If you use the icon of the main window, the index of the icon of the Delphi compiled program is 0.

This example is debugged in Win2000 and Delphi6

转载请注明原文地址:https://www.9cbs.com/read-27507.html

New Post(0)