How to Assign a Custom Icon to a File Type
引用网址:https://docs.microsoft.com/en-us/windows/win32/shell/how-to-assign-a-custom-icon-to-a-file-type
When no custom default icon is assigned to a file type, the desktop and Windows Explorer display all files of that type with a generic default icon. For example, the following screen shot shows this default icon used with the MyDocs4.myp file.
While all the files displayed in this screen shot are simple text files, only MyDocs4.myp displays the Windows default icon. This is because the .txt extension is a registered file type that has a custom default icon.
The following screen shot shows a custom icon that has been assigned to the .myp file type.
Note
Icons can also be assigned on an application-specific basis.
Instructions
Step 1:
Create a subkey named DefaultIcon in one of the following two locations:
- For a file-type assignment, HKEY_CLASSES_ROOT\.extension
- For an application assignment, HKEY_CLASSES_ROOT\ProgID
Step 2:
Assign the DefaultIcon subkey a default value of type REG_SZ that specifies the fully qualified path for the file that contains the icon.
Step 3:
Call the SHChangeNotify function to notify the Shell to update its icon cache.
Remarks
The following example shows a detailed view of the registry entries that are required for a file-type icon assignment. The file name extension is associated with an application, but the icon assignment is to the file name extension itself so that the associated application does not dictate the default icon.
HKEY_CLASSES_ROOT
.myp
(Default) = MyProgram.1
DefaultIcon
(Default) = C:\MyDir\MyProgram.exe,2
The following example shows a detailed view of the registry entries that are required for an application icon assignment. The .myp file name extension is first associated with the MyProgram.1 application. The MyProgram.1 ProgID subkey is then assigned the custom default icon.
HKEY_CLASSES_ROOT
.myp
(Default) = MyProgram.1
MyProgram.1
DefaultIcon
(Default) = C:\MyDir\MyProgram.exe,2
Any file that contains an icon is acceptable, including .ico, .exe, and .dll files. If there is more than one icon in the file, the path should be followed by a comma, and then the index of the icon.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现