使用方法,如要注册 ".abc" 类型的文件:
RegisterShellFileType(".abc", "abcfile", "abc文件", "c:/abc/abc.exe", NULL, "c:/abc/abc.exe", 0);
代码:
void RegisterShellFileType( string ext_name, string type_name, string description, string exec, string args, string icon_file, int icon_index) { HKEY hKey; char szIndex[32] = {0}; RegCreateKey(HKEY_CLASSES_ROOT, ext_name.c_str(), &hKey); RegSetValue(hKey, "", REG_SZ, type_name.c_str(), type_name.length()); RegCloseKey(hKey); RegCreateKey(HKEY_CLASSES_ROOT, type_name.c_str(), &hKey); RegSetValue(hKey, "", REG_SZ, description.c_str(), description.length()); RegCloseKey(hKey); RegCreateKey(HKEY_CLASSES_ROOT, (type_name+"//DefaultIcon").c_str(), &hKey); itoa(icon_index, szIndex, 10); icon_file = icon_file + "," + szIndex; RegSetValue(hKey, "", REG_SZ, icon_file.c_str(), icon_file.length()); RegCloseKey(hKey); RegCreateKey(HKEY_CLASSES_ROOT, (type_name+"//Shell//Open//Command").c_str(), &hKey); exec = exec + " " + args + " /"%1/""; RegSetValue(hKey, "", REG_SZ, exec.c_str(), exec.length()); RegCloseKey(hKey); //刷新系统图标缓存 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_DWORD, NULL, 0); }
文章发布于 2008-01-06 16:19:00 CSDN,现转博客园。
sdragonx https://github.com/sdragonx