void CINIDlg::OnBnClickedBtnWrite() { CString strName,strPassword,strSQL,strtemp; DWORD strIP; BYTE ip0,ip1,ip2,ip3; m_ctlIP.GetAddress(ip0,ip1,ip2,ip3); m_ctlName.GetWindowTextW(strName); m_ctlPassword.GetWindowTextW(strPassword); m_ctlSQL.GetWindowTextW(strSQL); //strtemp.Format(_T("%d"),strIP); CString strl; strl=""; char temp1[10],temp2[10],temp3[10],temp4[10]; itoa(ip0,temp1,10); itoa(ip1,temp2,10); itoa(ip2,temp3,10); itoa(ip3,temp4,10); strl+=temp1; strl+="."; strl+=temp2; strl+="."; strl+=temp3; strl+="."; strl+=temp4; ::WritePrivateProfileString(_T("SqlInfo"),_T("SqlName"),strSQL,_T("c://SQL.ini")); ::WritePrivateProfileString(_T("SqlInfo"),_T("Name"),strName,_T("c://SQL.ini")); ::WritePrivateProfileString(_T("SqlInfo"),_T("Password"),strPassword,_T("c://SQL.ini")); ::WritePrivateProfileString(_T("SqlInfo"),_T("SqlIP"),strl,_T("c://SQL.ini")); AfxMessageBox(_T("写入完成")); }
void CINIDlg::OnBnClickedBtnRead() { CString strName,strPassword,strSQL,strl; GetPrivateProfileString(_T("SqlInfo"),_T("SqlName"),_T("默认设置"),strSQL.GetBuffer(MAX_PATH),MAX_PATH,_T("c://SQL.ini")); GetPrivateProfileString(_T("SqlInfo"),_T("Name"),_T("默认设置"),strName.GetBuffer(MAX_PATH),MAX_PATH,_T("c://SQL.ini")); GetPrivateProfileString(_T("SqlInfo"),_T("Password"),_T("默认设置"),strPassword.GetBuffer(MAX_PATH),MAX_PATH,_T("c://SQL.ini")); GetPrivateProfileString(_T("SqlInfo"),_T("SqlIP"),_T("默认设置"),strl.GetBuffer(MAX_PATH),MAX_PATH,_T("c://SQL.ini")); m_ctlSQL.SetWindowTextW(strSQL); m_ctlName.SetWindowTextW(strName); m_ctlPassword.SetWindowTextW(strPassword); char*ca=(LPSTR)strl.GetBuffer(strl.GetLength()); char dest[255]; wcstombs(dest,strl.GetString(),255); DWORD dwIP = inet_addr(dest); unsigned char *pIP = (unsigned char*)&dwIP; m_ctlIP.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3)); }