有时候我们要在浏览网页时打开画图、计算器、记事本、自己的一些程序什么的,于是会把浏览器最小化,慢慢找。难道电脑用起来一定要这么蛋疼吗?非也,其实只要轻松设置一下,就可以在地址栏输入快速打开了。
如图:
先设置下:
注册表情况:
输入:cal:// (IE中后面要加任意字符串)
--------------------------------------------------------------------------------------------------------------------------------------
下面是注册表情况:Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\cal]
"URL Protocol"=""
[HKEY_CLASSES_ROOT\cal\DefaultIcon]
@="calc.exe, 0"
[HKEY_CLASSES_ROOT\cal\Shell]
[HKEY_CLASSES_ROOT\cal\Shell\open]
[HKEY_CLASSES_ROOT\cal\Shell\open\command]
@="\"calc.exe\" \"%1\""
保存为reg文件导入就行了。
--------------------------------------------------------------------------------------------------------------------------------------
下面是源码:
//头文件WebCustomProtocolDlg.h
class CWebCustomProtocolDlg : public CDialog
{
// Construction
public:
CWebCustomProtocolDlg(CWnd* pParent = NULL);// standard constructor
HKEY hKey; //..........省略
}
//Cpp文件WebCustomProtocolDlg.cpp
//由于加入了非API,所以要引用一个库
#include <SHLWAPI.H>
#pragma comment(lib, "Shlwapi.lib")
//这是控件与变量的关系
DDX_Text(pDX, IDC_ASSOCIATEDAPP, m_app); //接口文件名称编辑框
DDX_Text(pDX, IDC_ICONINDEX, m_icon); //图标序号编辑框
DDX_Text(pDX, IDC_PROTOCONAME, m_pro); //注册协议编辑框
void CWebCustomProtocolDlg::OnOK()
{
UpdateData(TRUE);
if (m_pro == "")
{
AfxMessageBox("协议为空!");
return;
}
if (m_app == "")
{
AfxMessageBox("程序为空!");
return;
}
if (m_icon == "")
{
AfxMessageBox("图标为空!");
m_icon = "0";
}
//创建子键写键值
DWORD dw = REG_CREATED_NEW_KEY;
DWORD keyType = REG_SZ;
CString temp = m_pro;
LPSTR lpPath = "";
if ((RegCreateKeyEx(HKEY_CLASSES_ROOT, temp, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
if ((RegSetValueEx(hKey, "URL Protocol", 0, REG_SZ, NULL, 0)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = m_pro + "\\DefaultIcon";
if ((RegCreateKeyEx(HKEY_CLASSES_ROOT, temp, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = m_app + ", " + m_icon;
lpPath = (LPSTR)(LPCTSTR)temp;
if ((RegSetValueEx(hKey, "", 0, REG_SZ, (CONST BYTE*)lpPath, MAX_PATH)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = m_pro + "\\Shell";
if ((RegCreateKeyEx(HKEY_CLASSES_ROOT, temp, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = temp + "\\open";
if ((RegCreateKeyEx(HKEY_CLASSES_ROOT, temp, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = temp + "\\command";
if ((RegCreateKeyEx(HKEY_CLASSES_ROOT, temp, 0, REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE|KEY_READ, NULL, &hKey, &dw)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
temp = "\"" + m_app + "\" \"\%1\"";
lpPath = (LPSTR)(LPCTSTR)temp;
if ((RegSetValueEx(hKey, "", 0, REG_SZ, (CONST BYTE*)lpPath, MAX_PATH)) != ERROR_SUCCESS)
{
AfxMessageBox("注册协议失败!");
return;
}
RegCloseKey(hKey);
return;
CDialog::OnOK();
}
void CWebCustomProtocolDlg::OnCancel()
{
UpdateData(TRUE);
if (m_pro == "")
{
AfxMessageBox("协议为空!");
return;
}
if ((RegOpenKey(HKEY_CLASSES_ROOT, (LPCTSTR)m_pro, &hKey)) != ERROR_SUCCESS)
{
AfxMessageBox("卸载协议失败!");
return;
}
if ((SHDeleteKey(HKEY_CLASSES_ROOT, (LPCTSTR)m_pro)) != ERROR_SUCCESS)
{
AfxMessageBox("卸载协议失败!123");
return;
}
RegCloseKey(hKey);
return;
CDialog::OnCancel();
}
void CWebCustomProtocolDlg::OnClose()
{
exit(0);
CDialog::OnClose();
}
-----------------------------------------------------------------------------------------------------------------
程序好了,现在注册下,是不是很有感觉?再也不用去开始-程序-附件慢慢找了,呵呵~
转载请注明:http://www.cnblogs.com/ZzzZzz