CString m_strOwner,m_strCompany;
void CregDlg::OnBnClickedQuery()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
HKEY hKEY;
LPCTSTR data_Set=_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\");
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0,KEY_READ,&hKEY));
if (ret0!=ERROR_SUCCESS)
{
AfxMessageBox(_T("error"));
return;
}
LPBYTE company_Get=new BYTE[160];
DWORD type_2=REG_SZ;
DWORD cbData_2=160;
long ret2=::RegQueryValueEx(hKEY,_T("RegisteredOrganization"),NULL,&type_2,company_Get,&cbData_2);
if (ret2!=ERROR_SUCCESS)
{
AfxMessageBox(_T("error1"));
return;
}
int i=0;
for(i=0;i<m_strCompany.GetLength()+1;i++)
// while(CString(company_Get+2*i)!="")
{
m_strCompany+=CString(company_Get+2*i);
// i++;
}
// AfxMessageBox(m_strCompany);
// m_strCompany=CString(company_Get);
GetDlgItem(IDC_EDIT1)->SetWindowText(m_strCompany);
m_strCompany="";
delete [] company_Get;
::RegCloseKey(hKEY);
UpdateData(FALSE);
}
void CregDlg::OnBnClickedChange()
{
// TODO: 在此添加控件通知处理程序代码
UpdateData(TRUE);
HKEY hKEY;
LPCTSTR data_set=_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\");
long ret0=(::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_set,0,KEY_WRITE,&hKEY));
if (ret0!=ERROR_SUCCESS)
{
AfxMessageBox(_T("error"));
return;
}
GetDlgItem(IDC_EDIT2)->GetWindowText(m_strCompany);
LPBYTE company_Set=(LPBYTE)m_strCompany.GetBuffer(m_strCompany.GetLength()+1);
DWORD type_2=REG_SZ;
DWORD cbData_2=2*m_strCompany.GetLength()+1;
long ret2=::RegSetValueEx(hKEY,_T("RegisteredOrganization"),NULL,type_2,company_Set,cbData_2);
if (ret2!=ERROR_SUCCESS)
{
AfxMessageBox(_T("error1"));
return;
}
else
{
AfxMessageBox(_T("注册表修改完成"));
}
m_strCompany="";
::RegCloseKey(hKEY);
UpdateData(FALSE);
}