void GetIniFile()
{
CString exeName = AfxGetApp()->m_pszExeName;
CString instPath = GetInstallPath();
CString iniPath;
iniPath.Format(_T("%s\\%s.ini"), instPath, exeName);
}
CString GetInstallPath()
{
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
int nPos;
nPos=sPath.ReverseFind('\\');
sPath=sPath.Left(nPos);
return sPath;
}
void OnWrite()
{
SYSTEMTIME st;
CString strDate;
GetLocalTime(&st);
strDate.Format(_T("%4d-%2d-%2d %2d:%2d:%2d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
std::string str = CStringA(strDate);
ofstream os(_T("E:\\123.txt"), ios::out);
os << str.c_str() << ": " << "wewrwerw我是中国" << endl;
os << str.c_str() << ": " << "13323424我是中国" << endl;
os << "END";
os.close();
}
void OnBnClickedBtnDownload()
{
CString sPath = _T("E:\\");
CString url = _T("\\\\10.1.7.29\\软件技术部\\椅旁soft\\123.txt");
CString filename = sPath + (_T("1234.txt"));
CInternetSession session;
CInternetFile* file = (CInternetFile*)session.OpenURL(url, 1, INTERNET_FLAG_TRANSFER_BINARY);
if (file == NULL)
{
file->Close();
delete file;
session.Close();
MessageBox(_T("下载文件失败! 错误代码:1"), _T("提示"), MB_ICONERROR);
return;
}
CString name = filename;
CFile file1;
if (file1.Open(name, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary, NULL))
{
int readlen = -1;
char buf[1024];
while (1)
{
readlen = file->Read(buf, 1024);
if (readlen == 0)
{
break;
}
file1.Write(buf, readlen);
ZeroMemory(buf, 1024);
}
file1.Close();
}
else
{
MessageBox(_T("下载文件失败! 错误代码:2"), _T("提示"), MB_ICONERROR);
file->Close();
delete file;
session.Close();
return;
}
file->Close();
delete file;
session.Close();
}