一个可执行程序exe如何关联多种类型文件?

rubyhlp0925 2010-07-16 02:15:41
请教:

如word 一样,双击doc或者dot都可以用word打开。

我的程序zoe.exe可以保存两种类型文件 .abt .abs,目前只做到双击abs就会用zoe.exe打开或者直接先开启zoe.exe然后选择打开.abt,这样才可以,如何做到双击abt,或abs都能用zoe.exe打开
...全文
144 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
js2854 2010-07-16
  • 打赏
  • 举报
回复
要关联两种文件类型,调用两次上面的函数,分别设置不同扩展名即可
js2854 2010-07-16
  • 打赏
  • 举报
回复
void  RegisterFileRelation(char *strExt/*要关联的文件后缀,上面写错了*/, char *strAppName, char *strAppKey, char *strDefaultIcon, char *strDescribe)
js2854 2010-07-16
  • 打赏
  • 举报
回复
我这有个设置文件关联的函数,可以直接调用,参考一下

//---------------------------------------------------------------------------
// 检测文件关联情况
// strExt: 要检测的扩展名(例如: ".txt_aes")
// 返回TRUE: 表示已关联,FALSE: 表示未关联
BOOL CheckFileRelation(const char *strExt)
{
HKEY hExtKey;
char AppKey[_MAX_PATH];
DWORD dwSize=sizeof(AppKey);
if(RegOpenKey(HKEY_CLASSES_ROOT,strExt,&hExtKey)==ERROR_SUCCESS)
{//若打开成功,说明已经关联
RegQueryValueEx(hExtKey,NULL,NULL,NULL,(LPBYTE)AppKey,&dwSize);
RegCloseKey(hExtKey);
//检查注册表项值,如符合返回TRUE
if (strcmp(AppKey,strExt+1)==0)
{
return TRUE;
}
//不符合返回FALSE
return FALSE;
}
return FALSE;
}

//---------------------------------------------------------------------------
// 注册文件关联
// 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,_T(""),REG_SZ,strAppKey,(DWORD)(strlen(strAppKey)+1));
RegCloseKey(hKey);

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

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

sprintf(strTemp,"%s\\Shell",strAppKey);
RegCreateKey(HKEY_CLASSES_ROOT,strTemp,&hKey);
RegSetValue(hKey,"",REG_SZ,"Open",(DWORD)(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,(DWORD)(strlen(strTemp)+1));
RegCloseKey(hKey);

SHChangeNotify(0x8000000, 0, 0, 0);
}
zwfgdlc 2010-07-16
  • 打赏
  • 举报
回复
改注册表,跟一些播放器一样,关联多种格式
天地英豪 2010-07-16
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 visualeleven 的回复:]
http://blog.csdn.net/wirror800/archive/2009/03/23/4016694.aspx
HKEY_CLASSES_ROOT\.ff = Ff.Document
HKEY_CLASSES_ROOT\SingleInstMDI.Document\shell\open\command = ff.EXE %1
HKEY_CLASSES_ROOT\SingleInstMDI.Document\shell\open\ddeexec = [open("%1")]
HKEY_CLASSES_ROOT\SingleInstMDI.Document\shell\open\ddeexec\application = ff
[/Quote]
rubyhlp0925 2010-07-16
  • 打赏
  • 举报
回复
不详细。。如何改注册表。是否有相关关联两种类型以上相关sample?
wltg2001 2010-07-16
  • 打赏
  • 举报
回复
这个要改注册表

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧