记事本的打开功能
OPENFILENAME ofn;
char szFile[MAX_PATH];
ZeroMemory(&ofn,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.lpstrFile=szFile;
ofn.lpstrFile[0]=TEXT('\0');
ofn.nMaxFile=sizeof(ofn);
ofn.lpstrFilter=TEXT("ALL\0*.*\0Text\0*.TXT\0");
ofn.nFilterIndex=1;
ofn.lpstrFileTitle=NULL;
ofn.nMaxFileTitle=0;
//ofn.hwndOwner=hwnd;
ofn.lpstrInitialDir=NULL;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
if(GetOpenFileName(&ofn))
{
//fileHandle=fopen(szFile,"r");
CFile file;
UINT length;
CString buf;
file.Open(szFile,CFile::modeRead);
length=file.GetLength();
//file.Read(buf.GetBuffer(length),length);
file.Read(buf.GetBuffer(length),length);
richeditText=buf;
UpdateData(false);
file.Close();
}
老师要求写一个记事本程序,打开文件的是偶遇到困难了。文件后面几个字是乱码。求指点
[解决办法]
参考Notepad++源代码?