在魅族M8手機(WinCE6.0系統)上編程設定檔案關聯(C/C++源碼)

來源:互聯網
上載者:User

 

在魅族M8手機(WinCE6.0系統)上設定檔案關聯,需產生以下登錄機碼:

 

HKEY_CLASSES_ROOT/.xxx

    defaultvalue: xxxfile

HKEY_CLASSES_ROOT/FileAssociate/xxxfile/shell

    defaultvalue: <path_of_exe>

HKEY_CLASSES_ROOT/FileAssociate/xxxfile

    DefaultIcon: <path_of_icon>

 

其中 xxx 指代欲關聯的檔案名稱尾碼,<path_of_exe> 指代欲關聯到的EXE檔案,<path_of_icon> 為被關聯檔案的預設顯示表徵圖。

此外,<path_of_exe> 啟動後應讀取進程命令列,GetCommandLine()傳回值(如果非空)即為其欲開啟的關聯檔案。

 

以下是設定檔案關聯的代碼:

 

bool RegisterJarFile()<br />{<br />bool bOK = false;<br />HKEY hKeyJar = 0;<br />DWORD dwDisposition = 0;<br />RegCreateKeyEx(HKEY_CLASSES_ROOT, L".jar", 0, NULL, 0, 0, NULL, &hKeyJar, &dwDisposition);<br />if(hKeyJar)<br />{<br />if(RegSetValueEx(hKeyJar, NULL, 0, REG_SZ, (const BYTE*)L"jarfile", wcslen(L"jarfile")*sizeof(WCHAR)) == ERROR_SUCCESS)<br />{<br />HKEY hKeyJarFile = 0;<br />const WCHAR* szJarFile = L"FileAssociate//jarfile";<br />RegCreateKeyEx(HKEY_CLASSES_ROOT, szJarFile, 0, NULL, 0, 0, NULL, &hKeyJarFile, &dwDisposition);<br />if(hKeyJarFile)<br />{<br />WCHAR buffer[256] = {0};<br />GetFullPathFileName(buffer, 256, L"jar.png");<br />RegSetValueEx(hKeyJarFile, L"DefaultIcon", 0, REG_SZ, (const BYTE*)buffer, wcslen(buffer)*sizeof(WCHAR));<br />HKEY hKeyShell = 0;<br />RegCreateKeyEx(hKeyJarFile, L"shell", 0, NULL, 0, 0, NULL, &hKeyShell, &dwDisposition);<br />if(hKeyShell)<br />{<br />GetFullPathFileName(buffer, 256, L"m8jad.exe");<br />bOK = (RegSetValueEx(hKeyShell, NULL, 0, REG_SZ, (const BYTE*)buffer, wcslen(buffer)*sizeof(WCHAR)) == ERROR_SUCCESS);<br />RegCloseKey(hKeyShell);<br />}<br />RegCloseKey(hKeyJarFile);<br />}<br />}<br />RegCloseKey(hKeyJar);<br />}<br />return bOK;<br />}

 

以下是處理命令列的代碼:

 

virtual BOOL OnInitDialog()<br />{<br />//......<br />WCHAR* szCommandLine = GetCommandLine();<br />if(szCommandLine && szCommandLine[0])<br />{<br />CreateJad(szCommandLine);<br />}<br />//......<br />}

 

強調幾點:xxxfile 位於 HKEY_CLASSES_ROOT/FileAssociate 之下,而非 HKEY_CLASSES_ROOT,其下的 "shell" 而非 "shell/open/command",shell 的索引值是 "<path_of_exe>" 而非 "<path_of_exe> %1",GetCommandLine()傳回值即是系統傳入的命令列參數(不包括本進程檔案名稱)。以上幾點與案頭PC編程有較大不同。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.