如何实现文件关联
来源:互联网 发布:护士资格考试题库软件 编辑:程序博客网 时间:2024/06/05 16:07
文件关联,网上资料不多,提供了两个简单的函数,使用方便。
#include <windows.h>
#include <stdio.h>
//---------------------------------------------------------------------------
// 检测文件关联情况
// 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);
}
- 如何实现文件关联
- 如何实现文件关联
- 如何关联,打开文件?
- 如何关联库文件
- 如何实现JMeter关联
- vc++实现文件关联
- C#实现文件关联
- VC 实现文件关联
- c++ 文件关联实现
- vc++实现文件关联
- VC 实现文件关联
- VC++实现文件关联
- vc++实现文件关联
- C++实现文件关联
- C# 实现文件关联
- 如何修复msc文件关联
- 如何取消文件的关联
- Hadoop如何实现关联计算
- OpenFire + jwchat 即时消息最新版安装调试
- oracle 字符串长度
- freetype和我的.cpp一起编译
- c#获得本机计算机名字,获得本机当前系统登陆用户和管理员权限,Environment
- C++中内存的五种分配方式
- 如何实现文件关联
- 写一个简单的可变参数的C函数
- 常见的视频、音频、图片文件的格式
- 软件开发的效率
- 我要在CSDN开辟自己的一片小天地~
- SPI、I2C、UART三种串行总线协议的区别
- Java事务处理总结
- API声明类
- 转载(只用于学习)