在OnInitDialog()下加下面修改注册表的内容
HKEY hKey;
LPCTSTR data_set = "Software\\Microsoft\\Windows\\CurrentCersion\\Run";
long ret0 = ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_set,0,KEY_WRITE,&hKey);
if(ret0!=ERROR_SUCCESS)
{
MessageBox("打开注册表时出现错误!");
}
CString m_filename;
GetModuleFileName(NULL,(char*)(LPCTSTR)m_filename,MAX_PATH);
m_filename = (CString)m_filename;
int length = m_filename.GetLength();
LPBYTE lpb = new BYTE[length+1];
for(int i=0;i<length;i++)
{
lpb[i] = m_filename[i];
}
lpb[length] = 0;
long ret1=::RegSetValueEx(hKey,"TestRun",NULL,REG_SZ,lpb,length+1);
if(ret1!=ERROR_SUCCESS)
{
MessageBox("写注册表时出现错误!");
}
delete lpb;
::RegCloseKey(hKey);