zoukankan      html  css  js  c++  java
  • (vc)注册文件关联

    昨天工作中用到了文件关联,查阅了一些网上的资料,经过整理写下了下面的代码并验证通过,现记录下面,以备以后查阅。

    /****************************************************
    * 检测文件关联情况
    * 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: 文件类型描述

    ****************************************************/

    BOOL RegisterFileRelation(char *strExt, char *strAppName, char *strAppKey, char *strDefaultIcon, char *strDescribe)
    {
    CRegKey regkey;
    char strTemp[_MAX_PATH];
    HKEY hKey;

    if (regkey.Create(HKEY_CLASSES_ROOT, strExt) != ERROR_SUCCESS)
    {
    return FALSE;
    }
    regkey.SetStringValue(NULL, strAppKey);

    regkey.Create(HKEY_CLASSES_ROOT, strAppKey);
    regkey.SetStringValue(NULL, strDescribe);

    sprintf(strTemp,"%s\DefaultIcon",strAppKey);
    regkey.Create(HKEY_CLASSES_ROOT, strTemp);
    regkey.SetStringValue(NULL, strDefaultIcon);

    sprintf(strTemp,"%s\Shell",strAppKey);
    regkey.Create(HKEY_CLASSES_ROOT, strTemp);
    regkey.SetStringValue(NULL, "Open");

    sprintf(strTemp,"%s\Shell\Open\Command",strAppKey);
    regkey.Create(HKEY_CLASSES_ROOT, strTemp);

    sprintf(strTemp,""%s" %%1"",strAppName);
    regkey.SetStringValue(NULL, strTemp);
    regkey.Close();

    // 通知系统,文件关联改变了
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST,NULL,NULL);

    }

  • 相关阅读:
    Webstorm 2018|2019 官网各大版本破解永久有效
    如何在IDEA 中使用Git
    maven的安装与配置(本地仓库、阿里云镜像设置)
    如何设置使chrome新标签页中打开链接自动跳转到新标签页?
    VMware虚拟机安装Linux系统
    Git安装和使用
    Navicat Premium 12.0.18 安装与激活
    HBuilder mui 报错No 'Access-Control-Allow-Origin' header
    spring+redis 报错 org.springframework.core.serializer.support.DeserializingConverter.<init>(Ljava/lang/ClassLoader;)V
    JAVA 注解
  • 原文地址:https://www.cnblogs.com/sheizhuchenfu/p/4156790.html
Copyright © 2011-2022 走看看