注册新的文件类型(如*.future*文档类型)

想要在注册表中注册新的文件类型,只需要在注册表中添加两项值:一是对扩展名的注册,二是对扩展名的操作信息进行注册。以下以*.future*为例,说明详细的编程过程,并且设定.future文档的默认打开方式为写字本,这样新建一个.future文档以后,双击时就不会出现让你选择打开方式的对话框。

void CShellFileDialogDlg::OnRegisternew()
{
 // TODO: Add your control notification handler code here
 CString strfileextention,strfileinfo,stropenway;
 strfileextention=".future";
 strfileinfo="future文档";
 stropenway="C://WINDOWS//notepad.exe %1";//写字板的打开.exe文件的所在路径

 HKEY phkdotfuture,phkroot,phkfileinfo,phkfileshellnew;
 HKEY phkfileinfoshell,phkfileopen,phkfileprint,phkfileopencommand;

 long result;
 result=RegOpenKey(HKEY_CLASSES_ROOT,NULL,&phkroot);
 if (result!=ERROR_SUCCESS) {
  MessageBox("打开注册表出错");
  return;
 }

 RegCreateKey(phkroot,strfileextention,&phkdotfuture);
 RegSetValue(phkdotfuture,NULL,REG_SZ,strfileinfo,strlen(strfileinfo));

 RegCreateKey(phkdotfuture,"ShellNew",&phkfileshellnew);
 BYTE temp;
 temp='/0';
 RegSetValueEx(phkfileshellnew,"NullFile",0,REG_SZ,&temp,1);

 RegCreateKey(phkroot,strfileinfo,&phkfileinfo);
 RegSetValue(phkfileinfo,NULL,REG_SZ,strfileinfo,strlen(strfileinfo));

 RegCreateKey(phkfileinfo,"Shell",&phkfileinfoshell);
 RegCreateKey(phkfileinfoshell,"Print",&phkfileprint);
 RegCreateKey(phkfileinfoshell,"Open",&phkfileopen);
 RegCreateKey(phkfileopen,"command",&phkfileopencommand);

 RegSetValue(phkfileopencommand,NULL,REG_SZ,stropenway,strlen(stropenway));

 MessageBox("新文件类型:future文档,注册完成");
}

运行的结果图片已经上传,当你右击鼠标时,出现新建.future文档,新建以后,双击即可以写字板方式打开。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值