如果用户没有这样做,我想设置文件的扩展名并将文件名和扩展组合框字符串连接起来。是否有一些简单的方法可以做到这一点,或者我需要一些“钩子”?
OPENFILENAME ofn; // common dialog box structure
TCHAR szFile[260]; // buffer for file name
HANDLE hFile; // file handle
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = 0;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("Текстові файли(*.txt)\0*.txt\0Word(*.doc)\0*.doc\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_EXPLORER;
if(GetSaveFileName(&ofn) == TRUE)
{
hFile = CreateFile( szFile,
GENERIC_WRITE,
0,
(LPSECURITY_ATTRIBUTES)NULL,
CREATE_NEW,
FILE_ATTRIBUTE_NORMAL,
(HANDLE)NULL);
int editLen = Edit_GetTextLength(edit);
TCHAR* buffer = new TCHAR[editLen+1];
DWORD wroteLen = 0;
Edit_GetText(edit,buffer,editLen+1);
//Set extension if need
///////////////////////
if(!WriteFile(hFile,buffer,editLen*sizeof(TCHAR),&wroteLen,NULL))
MessageBox(hwnd,_T("File wasn`t saved.."),_T("Error"),MB_ICONERROR);
CloseHandle(hFile);
delete[]buffer;
感谢您的回复!))