VC 实现文件关联

简介: 文件关联的两个简单函数 //--------------------------------------------------------------------------- // 检测文件关联情况 // strExt: 要检测的扩展名(例如: ".

文件关联的两个简单函数

//---------------------------------------------------------------------------
// 检测文件关联情况
// strExt: 要检测的扩展名(例如: ".txt")
// strAppKey: ExeName扩展名在注册表中的键值(例如: "txtfile")
// 返回TRUE: 表示已关联,FALSE: 表示未关联
BOOL CheckFileRelation(const char *strExt, const char *strAppKey)
{
int nRet=FALSE;
HKEY hExtKey;
char szPath[_MAX_PATH];
DWORD dwSize=sizeof(szPath);
if(RegOpenKey(HKEY_CLASSES_ROOT,strExt,&hExtKey)==ERROR_SUCCESS)
{
RegQueryValueEx(hExtKey,NULL,NULL,NULL,(LPBYTE)szPath,&dwSize);
if(_stricmp(szPath,strAppKey)==0)
{
nRet=TRUE;
}
RegCloseKey(hExtKey);
return nRet;
}
return nRet;
}

//---------------------------------------------------------------------------
// 注册文件关联
// strExe: 要检测的扩展名(例如: ".txt")
// strAppName: 要关联的应用程序名(例如: "C:\MyApp\MyApp.exe")
// strAppKey: ExeName扩展名在注册表中的键值(例如: "txtfile")
// strDefaultIcon: 扩展名为strAppName的图标文件(例如: "C:\MyApp\MyApp.exe,0")
// strDescribe: 文件类型描述
void RegisterFileRelation(char *strExt, char *strAppName, char *strAppKey, char *strDefaultIcon, char *strDescribe)
{
char strTemp[_MAX_PATH];
HKEY hKey;

RegCreateKey(HKEY_CLASSES_ROOT,strExt,&hKey);
RegSetValue(hKey,"",REG_SZ,strAppKey,strlen(strAppKey)+1);
RegCloseKey(hKey);

RegCreateKey(HKEY_CLASSES_ROOT,strAppKey,&hKey);
RegSetValue(hKey,"",REG_SZ,strDescribe,strlen(strDescribe)+1);
RegCloseKey(hKey);

sprintf(strTemp,"%s\\DefaultIcon",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey,"",REG_SZ,strDefaultIcon,strlen(strDefaultIcon)+1);
RegCloseKey(hKey);

sprintf(strTemp,"%s\\Shell",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey,"",REG_SZ,"Open",strlen("Open")+1);
RegCloseKey(hKey);

sprintf(strTemp,"%s\\Shell\\Open\\Command",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
sprintf(strTemp,"%s \"%%1\"",strAppName);
RegSetValue(hKey,"",REG_SZ,strTemp,strlen(strTemp)+1);
RegCloseKey(hKey);
}

目录
相关文章
VC6和VS2005(VC8)各项目默认运行时库
VC6和VS2005(VC8)各项目默认运行时库
VC7(VS2002)的arx项目转VC8(VS2005)项目,注意事项
VC7(VS2002)的arx项目转VC8(VS2005)项目,注意事项
VC通过函数名调用DLL的标准范例
VC通过函数名调用DLL的标准范例
54 0
|
C++ 索引
VC通过函数索引调用DLL范例
VC通过函数索引调用DLL范例
48 0
|
C# C++
VS2017下创建C++动态库导出符合并完成调用测试(DLL可供C#调用)
VS2017下创建C++动态库导出符合并完成调用测试(DLL可供C#调用)
394 0
VS2017下创建C++动态库导出符合并完成调用测试(DLL可供C#调用)
MFC更改菜单名称后进行编译还是原来的名称
问题: 用vc2010 随便弄一个有菜单的程序 然后使用资源管理器(在Menu那个树目录中)添加一个菜单,并加入对应的ID,编译运行,新添加的菜单正常显示 这个时候,我想更改一下新添加的菜单的名字 双击后打开属性,在cap...
1549 0
|
安全 编译器 C语言