Getsavefilename()样例代码片段
OPENFILENAME ofn;
TCHAR szFile[MAX_PATH];
ZeroMemory(&ofn,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = m_hWnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = _T('\0');
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("Text\0*.txt\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
CString strFile;
if (GetSaveFileName(&ofn))
{
strFile.Format(_T("%s"),szFile);
}
else
return;
if (strFile.Find(_T('.'))!= -1)
{
strFile = strFile.Left(strFile.Find(_T('.')));
}
strFile+=_T(".txt");
CStdioFile File;
CFileException fileException;
if (File.Open(strFile,CFile::typeText | CFile::modeCreate | CFile::modeReadWrite ))
{
char* old_local = _strdup(setlocale(LC_CTYPE,NULL));
setlocale(LC_CTYPE, "chs");
File.WriteString(_T("你现在还好吗?\r\n")
}