参考:http://www.2cto.com/kf/201303/193450.html
CString Site;
m_ctrlEdit_url.GetWindowText(Site);
for(int j=1; j<100; j++)
{//添加新项
HKEY hKey;
DWORD lp_disp;
//打开注册表
CString index;
index.Format("%d",j);
CString m_path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range" + index;
LONG lnRes = ::RegCreateKeyEx(
HKEY_CURRENT_USER,
m_path, //子目录路径
0L,//必须取0
NULL,
REG_OPTION_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&lp_disp);
//如果打开已有的或者不成功,则continue;
if(lp_disp == REG_OPENED_EXISTING_KEY || lnRes != ERROR_SUCCESS) continue;
LPBYTE Data = new BYTE[4];
int _Data[4] = {2,0,0,0};
for(int i=0; i<4; i++)
{
*(Data+i) = _Data[i];
}
lnRes = RegSetValueEx(hKey,
"*",
0,
REG_DWORD,
Data,
REG_DWORD );
unsigned char site_Data[30];
lstrcpy( (char *) site_Data , LPCTSTR(Site) );
lnRes = RegSetValueEx(hKey,
":Range",
0,
REG_SZ,
site_Data,
Site.GetLength()+1 );
//若果成功添加一个网址,则break; //如:http://hi.baidu.com网址
if( ERROR_SUCCESS == lnRes )
break;
else
AfxMessageBox("失败");
}