//创建临时文件
void OnCreateTempFile()
{
//get unique temporary file.
CString strFile;
GetuniqueTempName (strFile);
TRY
{
//Create file and write data.Note that file is closed
//in the destructor of the CFile object.
CFile file (strFile,CFile:: modeCreate | CFile:: modeWrite);
//write data
file.Write("temp",10);
file.Close();
}
CATCH (CFileException, e)
{
//error opening file
}
END_CATCH
void OnCreateTempFile()
{
//get unique temporary file.
CString strFile;
GetuniqueTempName (strFile);
TRY
{
//Create file and write data.Note that file is closed
//in the destructor of the CFile object.
CFile file (strFile,CFile:: modeCreate | CFile:: modeWrite);
//write data
file.Write("temp",10);
file.Close();
}
CATCH (CFileException, e)
{
//error opening file
}
END_CATCH
}
//获得临时文件的完整路径
void GetuniqueTempName(CString &strTempName)
{
//Get the temporary files directory.
TCHAR szTempPath [MAX_PATH];
DWORD dwResult=:: GetTempPath (MAX_PATH, szTempPath);
ASSERT (dwResult);
//Create a unique temporary file.
TCHAR szTempFile [MAX_PATH];
UINT nResult=GetTempFileName (szTempPath, _T ("~ex"),0,szTempFile);
ASSERT (nResult);
strTempName=szTempFile;
}