我给自己序列化出的文件设置了自己的后缀名,现在想为我的文件设置一个文件图标,该怎么做呢?
最好是在通过编程的方式完成,网上大多是delphi的例子,我想用vc实现。
望高手指点!
最好是在通过编程的方式完成,网上大多是delphi的例子,我想用vc实现。
望高手指点!
解决方案 »
- 还是线程的问题,很奇怪
- 各位用 Unicode 这么久了,难道没发现这么简单的一个问题么?
- 怎么让某个控件永远得不到焦点
- vc中用ado连接的access,如何获取数据库的字段名称啊?
- 新手提问(关于一个函数的用法)谢谢!
- 从cbutton派生一个类kbutton,使用时,在spy++中看到的类名字还是button而不是kbutton呢?
- 手写板的工作原理????
- VC中一个比较妖的问题,急!!!!!
- 打印的奇怪问题, 我在打印时只能把字符打印出来,却不能把图片打印出来,请各位高手帮忙了。
- 谁能给我一个再ASP里调用存储过程的例子
- windows陷阱分发机制的若干问题
- 我想通过修改IP包实现不同IP访问网站,能不能实现?
//strExt :扩展名 ,nTypeIcon:图标 strFileTypeDescribe 类型描述
BOOL RegisterFileType(string strExt, int nTypeIcon, CString &strFileTypeDescribe)
{
CString strExtentName = strExt.c_str(); // 要检测的扩展名(例如: ".txt")
CString strAppKey = TEXT("abc"); // 扩展名在注册表中的键值(例如: "abc.txtfile")
strAppKey += strExtentName + TEXT("file");
CString strAppName; // 要关联的应用程序名(例如: "C:\MyApp\MyApp.exe")
CString strDefaultIcon; // 扩展名为strAppName的图标文件(例如: "C:\MyApp\MyApp.exe,0")
CString strDescribe; // 文件类型描述
HKEY hKey; strDescribe = strFileTypeDescribe; // 获取程序路径
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
strAppName = szPath; #pragma region<</* 更新HKEY_CLASSES_ROOT下的文件类型相关选中项目 */>>
RegCreateKey(HKEY_CLASSES_ROOT, strExtentName, &hKey);
RegSetValue(hKey, TEXT(""), REG_SZ, strAppKey, strAppKey.GetLength());
RegCloseKey(hKey); RegCreateKey(HKEY_CLASSES_ROOT, strAppKey, &hKey);
RegSetValue(hKey, TEXT(""), REG_SZ, strDescribe, strDescribe.GetLength());
RegCloseKey(hKey); strDefaultIcon = strAppName;
CString strTemp;
strTemp.Format(TEXT(",%d"), nTypeIcon )
strDefaultIcon += strTemp;
strTemp = strAppKey + TEXT("\\DefaultIcon");
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey, TEXT(""), REG_SZ, strDefaultIcon, strDefaultIcon.GetLength());
RegCloseKey(hKey); CString strCmd = TEXT("Open");
strTemp = strAppKey + TEXT("\\Shell");
RegCreateKey(HKEY_CLASSES_ROOT, strTemp, &hKey);
RegSetValue(hKey, TEXT(""), REG_SZ, strCmd, strCmd.GetLength());
RegCloseKey(hKey); strTemp = strAppKey + TEXT("\\Shell\\Open\\Command");
RegCreateKey(HKEY_CLASSES_ROOT, strTemp, &hKey);
strCmd = strAppName + TEXT(" \"open %1\"");
RegSetValue(hKey, TEXT(""), REG_SZ, strCmd, strCmd.GetLength());
RegCloseKey(hKey); #pragma endregion #pragma region<</* 更新HKEY_CURRENT_USER */>> CString strNewKey;
strNewKey = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\");
strNewKey += strExtentName;
RegCreateKey(HKEY_CURRENT_USER, strNewKey, &hKey);
strTemp = TEXT("Progid");
#ifdef UNICODE
RegSetValueEx(hKey, strTemp, 0, REG_SZ, (BYTE*)strAppKey.GetBuffer(), strAppKey.GetLength()*2);
#else
RegSetValueEx(hKey, strTemp, 0, REG_SZ, (BYTE*)strAppKey.GetBuffer(), strAppKey.GetLength());
#endif
RegCloseKey(hKey); strNewKey += TEXT("\\OpenWithProgids");
RegCreateKey(HKEY_CURRENT_USER, strNewKey, &hKey);
strTemp = TEXT("");
RegSetValue(hKey, strAppKey, REG_NONE, strTemp, strTemp.GetLength());
RegCloseKey(hKey); #pragma endregion
return TRUE;
}
以后缀.aaa文件为例:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.aaa]
@="aaafile"
[HKEY_CLASSES_ROOT\aaafile]
@="PHP Script"
[HKEY_CLASSES_ROOT\aaafile\DefaultIcon]
@="D:\\Program Files\\PHP Designer 2007 - Professional\\phpdesigner2007.exe,0"
[HKEY_CLASSES_ROOT\aaafile\shell\open]
@="PHP Designer 2007"
[HKEY_CLASSES_ROOT\aaafile\shell\open\command]
@="D:\\Program Files\\PHP Designer 2007 - Professional\\phpdesigner2007.exe %1"