[原创]添加右键菜单 小工具
第一次发贴 有不足之处请见谅;
闲来无事,在网上看到一款小工具,是添加右键菜单的;
感觉挺好用的,就逆向之,了解了下原理;
顺便复习了下注册表的操作
关键代码如下
CString strKey = L"*\\shell\\";
HKEY hKey = NULL;
DWORD dwRead;
DWORD dwRet;
strKey += m_strName;
dwRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, strKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwRead);
if(dwRet != ERROR_SUCCESS)
{
return FALSE;
}
TRACE(L"%d, %d", _tcslen(m_strLnkName), m_strLnkName.GetLength());
dwRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)m_strLnkName.GetBuffer(), ((DWORD)_tcslen(m_strLnkName) + 1)*2);
if(dwRet != ERROR_SUCCESS)
{
return FALSE;
}
RegCloseKey(hKey);
hKey = NULL;
strKey += L"\\Command";
dwRet = RegCreateKeyEx(HKEY_CLASSES_ROOT, strKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwRead);
if(dwRet != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
CString strTmp;
strTmp += L"\"";
strTmp += m_strPath;
strTmp += L"\" \"%1\""; //后面添加 "%1"不知道是为什么
dwRet = RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)strTmp.GetBuffer(), ((DWORD)_tcslen(strTmp) + 1)*2);
if(dwRet != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return FALSE;
}
RegCloseKey(hKey);
return TRUE;附件上的代码vs2005编译通过 ;
