void CReadTEXTDlg::Open()
{
char strtemp[100000];
int f=0;
CString str;
SHFILEOPSTRUCT m_shfile;
TCHAR strch[MAX_PATH+1];
ZeroMemory(strch,MAX_PATH+1);
CFileFind finder;
BOOL bWorking;
CFileDialog m_fileDlg(true,"","penghao",OFN_HIDEREADONLY,
"Text Files (*.txt)|*.txt|cpp Files (*.cpp)|*.cpp||");
GetCurrentDirectory(MAX_PATH,m_strCurrentPath);
if (m_fileDlg.DoModal()==IDOK)
{ SetCurrentDirectory(m_strCurrentPath);
bWorking= finder.FindFile("story\\*.txt");
while(bWorking)
{
bWorking = finder.FindNextFile();
if (m_fileDlg.GetFileTitle()==finder.GetFileTitle())
{
AfxMessageBox("你打开的文件已经存在,请不要重复打开!");
return ; }
} CString strtemp1;
str=m_fileDlg.GetPathName();
_tcscpy(strch,str);
strch[str.GetLength()]=0;
ZeroMemory(&m_shfile,sizeof(m_shfile));
m_shfile.hwnd =HWND_DESKTOP;
m_shfile.fFlags=FOF_NOCONFIRMATION|FOF_SIMPLEPROGRESS;
m_shfile.wFunc=FO_COPY;
m_shfile.pFrom=strch;
m_shfile.pTo = "story\\";
SHFileOperation(&m_shfile);
if (m_file.Open(str,CFile::modeRead))
{
STRINF tempStr;
tempStr.s_fileName=m_fileDlg.GetFileTitle();
tempStr.s_filePath=m_shfile.pTo+m_fileDlg.GetFileName();
m_vector.push_back(tempStr);
str=m_fileDlg.GetFileTitle();
int a=m_file.Read(strtemp,100000);
strtemp[a-1]='\0';
SetDlgItemText(IDC_EDIT1,strtemp);
m_listBox.AddString(str);
if (m_listBox.GetCount()!=0)
{
hwnd=GetDlgItem(IDC_BUTTON1);
hwnd->EnableWindow(true);
hwnd=GetDlgItem(IDC_BUTTON2);
hwnd->EnableWindow(true); }
m_file.Close();
}else
{
AfxMessageBox("你要打开的文件不存在,请检查!");
}
}
}我现在遇到这个问题,如果我复制的文件名是以英文结尾的时候,文件名就会少以个字符不知道是什么原因!比如,我打开一个文件abcdef.txt那么复制到story\\目录下就变成abcde.txt,我不知道文件名为什么要少一个字符。。
{
char strtemp[100000];
int f=0;
CString str;
SHFILEOPSTRUCT m_shfile;
TCHAR strch[MAX_PATH+1];
ZeroMemory(strch,MAX_PATH+1);
CFileFind finder;
BOOL bWorking;
CFileDialog m_fileDlg(true,"","penghao",OFN_HIDEREADONLY,
"Text Files (*.txt)|*.txt|cpp Files (*.cpp)|*.cpp||");
GetCurrentDirectory(MAX_PATH,m_strCurrentPath);
if (m_fileDlg.DoModal()==IDOK)
{ SetCurrentDirectory(m_strCurrentPath);
bWorking= finder.FindFile("story\\*.txt");
while(bWorking)
{
bWorking = finder.FindNextFile();
if (m_fileDlg.GetFileTitle()==finder.GetFileTitle())
{
AfxMessageBox("你打开的文件已经存在,请不要重复打开!");
return ; }
} CString strtemp1;
str=m_fileDlg.GetPathName();
_tcscpy(strch,str);
strch[str.GetLength()]=0;
ZeroMemory(&m_shfile,sizeof(m_shfile));
m_shfile.hwnd =HWND_DESKTOP;
m_shfile.fFlags=FOF_NOCONFIRMATION|FOF_SIMPLEPROGRESS;
m_shfile.wFunc=FO_COPY;
m_shfile.pFrom=strch;
m_shfile.pTo = "story\\";
SHFileOperation(&m_shfile);
if (m_file.Open(str,CFile::modeRead))
{
STRINF tempStr;
tempStr.s_fileName=m_fileDlg.GetFileTitle();
tempStr.s_filePath=m_shfile.pTo+m_fileDlg.GetFileName();
m_vector.push_back(tempStr);
str=m_fileDlg.GetFileTitle();
int a=m_file.Read(strtemp,100000);
strtemp[a-1]='\0';
SetDlgItemText(IDC_EDIT1,strtemp);
m_listBox.AddString(str);
if (m_listBox.GetCount()!=0)
{
hwnd=GetDlgItem(IDC_BUTTON1);
hwnd->EnableWindow(true);
hwnd=GetDlgItem(IDC_BUTTON2);
hwnd->EnableWindow(true); }
m_file.Close();
}else
{
AfxMessageBox("你要打开的文件不存在,请检查!");
}
}
}我现在遇到这个问题,如果我复制的文件名是以英文结尾的时候,文件名就会少以个字符不知道是什么原因!比如,我打开一个文件abcdef.txt那么复制到story\\目录下就变成abcde.txt,我不知道文件名为什么要少一个字符。。
============
代码太长了,没仔细看,是不是改成strch[str.GetLength()+1]=0;