mfc//写入
CString strName;
CString strPwd;
CString strPath; bool strIsExist = false; GetDlgItem(IDC_EDIT1)->GetWindowText(strName);
GetDlgItem(IDC_EDIT2)->GetWindowText(strPwd);
GetDlgItem(IDC_EDIT3)->GetWindowText(strPath); //服务器验证帐号密码
//if()
//{
//
//}else
//{
//获取监视目录下所有文件信息,上传服务器,记录注册表
//初始化注册表
HKEY hkey; if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), 0, KEY_ALL_ACCESS, &hkey)!= ERROR_SUCCESS)
{
VERIFY(!RegCreateKey(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), &hkey));
}
VERIFY(!RegSetValueEx(hkey, _T("_IsExist"), 0, REG_DWORD, (BYTE *)&strIsExist, 4));
VERIFY(!RegSetValueEx(hkey, _T("_Name"), 0, REG_SZ, (BYTE *)strName.GetBuffer(strName.GetLength()), 500));
VERIFY(!RegSetValueEx(hkey, _T("_Pwd"), 0, REG_SZ, (BYTE *)strPwd.GetBuffer(strPwd.GetLength()), 500));
VERIFY(!RegSetValueEx(hkey, _T("_Path"), 0, REG_SZ, (BYTE *)strPath.GetBuffer(strPath.GetLength()), 500));
RegCloseKey(hkey);
//}//读取
unsigned char chbuf[500]; DWORD type(0);
DWORD len(500);
memset(chbuf, 0, sizeof(chbuf));
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS)
{
if (RegQueryValueEx(hkey, _T("_Name"), 0, &type, chbuf, &len) == ERROR_SUCCESS)
{
strName.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Pwd"), 0, &type, chbuf, &len))
{
strPwd.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Path"), 0, &type, chbuf, &len))
{
strPath.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_IsExist"), 0, &type, chbuf, &len))
{
strIsExist = chbuf[0];
} RegCloseKey(hkey);
}
CString strName;
CString strPwd;
CString strPath; bool strIsExist = false; GetDlgItem(IDC_EDIT1)->GetWindowText(strName);
GetDlgItem(IDC_EDIT2)->GetWindowText(strPwd);
GetDlgItem(IDC_EDIT3)->GetWindowText(strPath); //服务器验证帐号密码
//if()
//{
//
//}else
//{
//获取监视目录下所有文件信息,上传服务器,记录注册表
//初始化注册表
HKEY hkey; if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), 0, KEY_ALL_ACCESS, &hkey)!= ERROR_SUCCESS)
{
VERIFY(!RegCreateKey(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), &hkey));
}
VERIFY(!RegSetValueEx(hkey, _T("_IsExist"), 0, REG_DWORD, (BYTE *)&strIsExist, 4));
VERIFY(!RegSetValueEx(hkey, _T("_Name"), 0, REG_SZ, (BYTE *)strName.GetBuffer(strName.GetLength()), 500));
VERIFY(!RegSetValueEx(hkey, _T("_Pwd"), 0, REG_SZ, (BYTE *)strPwd.GetBuffer(strPwd.GetLength()), 500));
VERIFY(!RegSetValueEx(hkey, _T("_Path"), 0, REG_SZ, (BYTE *)strPath.GetBuffer(strPath.GetLength()), 500));
RegCloseKey(hkey);
//}//读取
unsigned char chbuf[500]; DWORD type(0);
DWORD len(500);
memset(chbuf, 0, sizeof(chbuf));
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\ShiYiZhong\\Settings"), 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS)
{
if (RegQueryValueEx(hkey, _T("_Name"), 0, &type, chbuf, &len) == ERROR_SUCCESS)
{
strName.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Pwd"), 0, &type, chbuf, &len))
{
strPwd.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Path"), 0, &type, chbuf, &len))
{
strPath.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_IsExist"), 0, &type, chbuf, &len))
{
strIsExist = chbuf[0];
} RegCloseKey(hkey);
}
if (RegQueryValueEx(hkey, _T("_Name"), 0, &type, chbuf, &len) == ERROR_SUCCESS)
{
strName.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Pwd"), 0, &type, chbuf, &len))
{
len = 500;
strPwd.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_Path"), 0, &type, chbuf, &len))
{
len = 500;
strPath.Format("%s", chbuf);
}
if (!RegQueryValueEx(hkey, _T("_IsExist"), 0, &type, chbuf, &len))
{
len = 500;
strIsExist = chbuf[0];
}RegQueryValueEx()调用后会改改len的值,每次要重新赋值.
{
strName.Format("%s", chbuf);
}len = 500;
if (!RegQueryValueEx(hkey, _T("_Pwd"), 0, &type, chbuf, &len))
{ strPwd.Format("%s", chbuf);
}len = 500;
if (!RegQueryValueEx(hkey, _T("_Path"), 0, &type, chbuf, &len))
{ strPath.Format("%s", chbuf);
}len = 500;
if (!RegQueryValueEx(hkey, _T("_IsExist"), 0, &type, chbuf, &len))
{ strIsExist = chbuf[0];
}