C++實現添加檔案關聯的方法

來源:互聯網
上載者:User

標籤:style   關聯   trap   roo   value   path   adc   ati   scribe   

// 檢測檔案關聯情況// 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: 要相關 App程式名(例如: "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);}//測試代碼//增加註冊表關聯        char strExt[10] = ".car";        char strAppKey[30] = "FW_readcar.1.0";        BOOL relationExists = CheckFileRelation(strExt, strAppKey);        if (!relationExists)        {                char strAppName[MAX_PATH + 1] = {0};                strcpy(strAppName,argv[0]);                char strDefaultIcon[MAX_PATH + 1] = "";                char strDescribe[100] = "WellTest Interpretation Files";                RegisterFileRelation(strExt, strAppName, strAppKey, strDefaultIcon, strDescribe);        }

 

C++實現添加檔案關聯的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.