MFC生成的窗口菜单中FILE->OPEN本身可以打开文件,但我想自己作一个,请教高手要如何编程?
void CNotepadView::OnEditFileOpen()
{
// TODO: Add your command handler code here
char szFileFilter[]=
"Source files(*.c)|*.c|"
"Source files(*.asm)|*.asm|"
"Text files(*.txt)|*.txt|"
"All files(*.*)|*.*||";
CFileDialog FileDlg(TRUE,"","",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,
szFileFilter,this);
FileDlg.m_ofn.lpstrTitle=_T("打开");
if(FileDlg.DoModal()!=IDOK)
return;
POSITION m_Pos;
CString TempString;
char AfxBuffer[100];
CWordElement* m_pWordElement;
LPCTSTR lpsz;
CStdioFile File;
if(!File.Open(FileDlg.GetPathName(),CFile::modeRead|CFile::typeText),NULL)
{
File.Abort();
MessageBox("打开文件操作失败","信息提示",MB_OK);
return;
}
else //从这边开始据我理解是不是应该有一个从文件中读取字符,然后再写到CEditView的工作区当中?
{ //这边是我自己瞎琢磨,运行没有错误,但工作区还是空白!!!
MessageBox("打开文件操作成功","信息提示",MB_OK);
m_Pos = m_WordList.GetHeadPosition();
while(m_Pos!=NULL)
{
m_pWordElement = ( CWordElement* ) m_WordList.GetNext(m_Pos);
TempString =m_pWordElement->Word;
lpsz=TempString.GetBuffer(20);
// AfxBuffer=TempString;
File.WriteString(lpsz);
}
}
}