VC 实现文件关联
来源:互联网 发布:淘宝商标设计 编辑:程序博客网 时间:2024/06/05 16:08
文件关联的两个简单函数
//---------------------------------------------------------------------------
// 检测文件关联情况
// 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);
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Y___Y/archive/2008/04/28/2340721.aspx
- vc++实现文件关联
- VC 实现文件关联
- vc++实现文件关联
- VC 实现文件关联
- VC++实现文件关联
- vc++实现文件关联
- Windows文件关联和VC实现
- VC 实现文件与应用程序关联
- 转:Windows文件关联和VC实现
- VC文件关联小结
- VC文件关联小结
- VC文件关联小结
- VC文件关联小结
- VC文件关联小结
- VC注册表文件关联,图标关联
- VC注册表文件关联,图标关联
- VC注册表文件关联,图标关联
- VC注册表文件关联,图标关联
- Mysql存储过程(二)——多结果集返回与java获取
- MFC中获取命令行参数的几种方法
- 欧几里得算法
- SQL Server 2005 智能感知插件 - SQL Prompt 3.8.0.224
- VC/MFC 设置程序与文件关联与双击文件获取文件路径
- VC 实现文件关联
- 所有程序员都应该至少读上两遍的十篇论文
- VC文件关联小结
- “ASP.NET(C#)Fans” QQ群:96877690
- 实验室智能防火检测系统——环境搭建(1)
- PC之父C. Thacker荣获2009年图灵奖
- C#中#region和#if的作用
- Mysql 卸载
- 单片机驱动蜂鸣器原理与设计