C++
void CAPPTestApp::RegisterProtocol()
{
CRegKey reg;
reg.Create(HKEY_CLASSES_ROOT,_T("vip"));
reg.SetStringValue(_T(""), _T("URL:vip Protocol"));
reg.SetStringValue(_T("URL Protocol"), _T(""));
DWORD size = MAX_PATH;
CString strPath;
::GetModuleFileName(m_hInstance, strPath.GetBuffer(MAX_PATH), size);
strPath.ReleaseBuffer();
reg.Create(HKEY_CLASSES_ROOT,_T("vip\\DefaultIcon"));
reg.SetStringValue(_T(""), strPath);
strPath += _T(" %1");
reg.Create(HKEY_CLASSES_ROOT,_T("vip\\shell\\open\\command"));
reg.SetStringValue(_T(""), strPath);
::MessageBox(HWND_DESKTOP, _T("The vip protocol has been registered"), _T("APPTest"), MB_OK);
}
用以上代码可以注册形如下方的注册表项:
HKEY_CLASSES_ROOT
vip
(Default) = "URL:vip Protocol"
URL Protocol= ""
DefaultIcon
(Default) = "c:\somepath\APPTest.exe"
shell
open
command
(Default) = "c:\somepath\APPTest.exe" "%1"