strResult += "\r\n";
SetDlgItemText(IDC_EDIT_RESULT,strResult);
}else{
CString strResult;
GetDlgItemText(IDC_EDIT_RESULT,strResult);
strResult += _T("请求发送成功,URL = ");
strResult += c_szRequestHost;
strResult += szTemp;
strResult += "\r\n";
SetDlgItemText(IDC_EDIT_RESULT,strResult);
}
printf("Error %d has occurred.\n",GetLastError());
// Close open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);*/
}catch( happyhttp::Wobbly& e )
{
printf("Exception:\n%s\n", e.what() );
}
}
void CUpdateIpDlg::stopUpdateInstance(){
CString strResult;
GetDlgItemText(IDC_EDIT_RESULT,strResult);
strResult += _T("停止更新请求:\r\n");
SetDlgItemText(IDC_EDIT_RESULT,strResult);
}
BOOL CUpdateIpDlg::setAutoStart(BOOL bVal){
HKEY hKey;
long return_val = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run",0,KEY_READ| KEY_WRITE,&hKey );
if (ERROR_SUCCESS == return_val)
{
if (bVal)
{
TCHAR pathtofile[MAX_PATH] = {0};
GetModuleFileName(NULL,pathtofile,MAX_PATH);
if (ERROR_SUCCESS != RegSetValueEx(hKey,_T("autoupdateip"),0,REG_SZ,(byte *)pathtofile,sizeof(pathtofile)))
{
RegCloseKey(hKey);
return FALSE;
}
}else{
long ret = RegDeleteva lue(hKey,_T("autoupdateip"));
if (ERROR_SUCCESS != ret && ret != ERROR_FILE_NOT_FOUND)
{
int err = GetLastError();
RegCloseKey(hKey);
return FALSE;
}
}
RegCloseKey(hKey);
return TRUE;
}
return FALSE;
}
void CUpdateIpDlg::OnBnClickedSave()
{
// TODO: Add your control notification handler code here
m_bAutoStart = ((CButton *)GetDlgItem(IDC_CHECK_AUTOSTART))->GetCheck();
if (!setAutoStart(m_bAutoStart))
{
MessageBox(_T("setAutoStart error!"));
}
m_nUpdateInterval = GetDlgItemInt(IDC_EDIT_UPDATEINTERVAL);
if (m_bIsRunning)
{
stopService();
startService(m_nUpdateInterval);
}
if(!saveSettings()){
MessageBox(_T("saveSettings error!"));
}else{
MessageBox(_T("saveSettings Success!"));
}
}
void CUpdateIpDlg::initSettings(){
m_strSettingFilepath = getSettingFilePath();
m_bAutoStart = (BOOL)GetPrivateProfileInt(_T("config"),_T("autostart"),1,m_strSettingFilepath);
m_nUpdateInterval = GetPrivateProfileInt(_T("config"),_T("updateinterval"),c_nDefaultUpdate,m_strSettingFilepath);
((CButton *)GetDlgItem(IDC_CHECK_AUTOSTART))->SetCheck(m_bAutoStart);
if (!setAutoStart(m_bAutoStart))
{
MessageBox(_T("setAutoStarterror"));
}
SetDlgItemInt(IDC_EDIT_UPDATEINTERVAL,m_nUpdateInterval);
}
BOOL CUpdateIpDlg::saveSettings(){
CString strTemp;
strTemp.Format(_T("%d"),m_bAutoStart);
if (!WritePrivateProfileString(_T("config"),_T("autostart"),strTemp,m_strSettingFilepath))
{
return FALSE;
}
strTemp.Format(_T("%d"), m_nUpdateInterval);
if (!WritePrivateProfileString(_T("config"),_T("updateinterval"),strTemp,m_strSettingFilepath))
{
return FALSE;
}
return TRUE;
}
CString CUpdateIpDlg::getSettingFilePath(){
TCHAR szPath[MAX_PATH] = {0};
BOOL bRet = SHGetSpecialFolderPath(NULL,szPath,CSIDL_APPDATA,FALSE);
if (!bRet)
{
MessageBox(_T("SHGetSpecialFolderPath Failed!"));
return _T("");
}
CString strFolder = szPat