我在程序里加了一个“打开样图”的菜单,希望从这里打开图形文件,没有实现,如果在classwizard自己生成的OpenDocument里就没问题,这是我的代码,是不是还要加点什么????
BOOL CMyWorkDoc::OnOpenDocument(LPCTSTR lpszPathName) ///这个函数可以打开图形文件
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
OFSTRUCT of;
HANDLE hFile=NULL;
hFile=(HANDLE)OpenFile(lpszPathName,&of,OF_READWRITE|OF_SHARE_COMPAT);
TRACE(lpszPathName);
if(hFile!=(HANDLE)HFILE_ERROR)
{
TRACE("SHAN CHU\n");
DWORD dwHighWord=NULL;
DWORD dwSizeLow=GetFileSize(hFile,&dwHighWord);
DWORD dwFileSize=dwSizeLow;
TRACE("dwFileSize=%d\n",dwFileSize);
if(dwFileSize==0)
{
TRACE("DA KAI\n");
POSITION viewPos=this->GetFirstViewPosition();
CMyWorkView* MyView=(CMyWorkView*)this->GetNextView(viewPos);
MyView->m_ObjectList.RemoveAll();
}
}
::CloseHandle(hFile);
return TRUE;
}
void CMyWorkDoc::On_MenuPicture_Read()///一样的代码在这里就不可以了
{
CFileDialog dlg(TRUE,"pic","*.pic");
if(dlg.DoModal()==IDOK)
{
OFSTRUCT of;
HANDLE hFile=NULL;
hFile=(HANDLE)OpenFile(dlg.GetPathName(),&of,OF_READWRITE|OF_SHARE_COMPAT);
if(hFile!=(HANDLE)HFILE_ERROR)
{
DWORD dwHighWord=NULL;
DWORD dwSizeLow=GetFileSize(hFile,&dwHighWord);
DWORD dwFileSize=dwSizeLow;
TRACE("dwFileSize=%d\n",dwFileSize);
if(dwFileSize==0)
{
POSITION viewPos=this->GetFirstViewPosition();
CMyWorkView* MyView=(CMyWorkView*)this->GetNextView(viewPos);
MyView->m_ObjectList.RemoveAll();
}
}
::CloseHandle(hFile);
CFile file;
// VERIFY(file.Open(dlg.GetPathName(),CFile::modeRead));
file.Open(dlg.GetPathName(),CFile::modeRead);
file.Close();
}