Discard the Windows default icon and let your program's directory have personalized folder icon! In fact, it is simple to do, in fact, only need a Desktop.ini file, I will explain the following from two aspects.
1. Manual mode:
First, create a Desktop.ini file in the folder you want to change, as follows:
[.ShellClassInfo]
ConfirmFileOp=0
InfoTip=我自己的文件夹
IconIndex=0
IconFile=MyFolder.ico
Explain:
The parameter confirmfileop is set to 0--the "You are removing system directory" warning when the user moves or deletes this folder.
The parameter iconfile is specified as the location of the icon file to be changed, which can be icon, BMP, EXE, or DLL file, and the image file in the example above is also placed in the same directory.
The parameter IconIndex can specify the index of the file, if this icon file is the image file, the IconIndex is set to 0.
Parameter infotip is used to set the ToolTip of this folder in Windows.
Next open cmd (Command Prompt) and enter:
attrib +s i:\MyFolder
I:\MyFolder refers to the path of the directory where I want to change the icon. This action is to make your folder a system folder.
Well, after manual processing now the catalog has changed style.
2. Programming Method:
This way is to use my favorite VB to achieve, it is also easy to achieve.
Only two API functions are required, one to manipulate the creation of the INI file, and the other to be equivalent to the attrib +s in manual mode.
Option Explicit
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function PathMakeSystemFolder Lib "shlwapi.dll" Alias "PathMakeSystemFolderA" (ByVal pszPath As String) As Long
Private Sub Form_Load()
'以下几步用于创建Desktop.ini文件
'不存在ini文件时,会自己创建ini
WritePrivateProfileString ".ShellClassInfo", "ConfirmFileOp", "0", App.Path & "\desktop.ini"
WritePrivateProfileString ".ShellClassInfo", "InfoTip", "我的文件夹因此而改变", App.Path & "\desktop.ini"
WritePrivateProfileString ".ShellClassInfo", "IconIndex", "0", App.Path & "\desktop.ini"
WritePrivateProfileString ".ShellClassInfo", "IconFile", "MyFolder.ico", App.Path & "\desktop.ini"
'让文件夹成为系统文件夹
PathMakeSystemFolder App.Path
End Sub
Further clarification is needed:
WritePrivateProfileString ".ShellClassInfo", "IconFile", "MyFolder.ico", App.Path & "\desktop.ini"
Can be changed to:
WritePrivateProfileString ".ShellClassInfo", "IconFile", App.EXEName & ".exe", App.Path & "\desktop.ini"
If you use the main window icon, the VB compiled program icon index is also used 0.