改变MFC中MDI默认打开方式(ID_FILE_OPEN)

来源:互联网 发布:mac魅可香港官网 编辑:程序博客网 时间:2024/06/10 04:19

在App类的CxxxApp::OnFileOpen()方法里不要调用CWinApp::OnFileOpen,而是调用自己的文件选择框取得文件路径,然后调用CWinApp::OpenDocumentFile打开文件。

如下:


void CMyPrjEditDemoApp::OnFileOpen() 
{
 // TODO: Add your command handler code here

 //下面是自己添加的文件打开对话框
 CFileDialog dlg(TRUE);
 int structsize = 0;

 DWORD dwVersion,dwWindowsMajorVersion,dwWindowsMinorVersion;

 dwVersion = GetVersion();
 dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
 dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));

 if(dwVersion<0x80000000)
  structsize=88;
 else
  structsize=76;


 //
 GISENV* env = _GetEnv();
  
 dlg.m_ofn.lpstrInitialDir = env->cur;
 dlg.m_ofn.lStructSize = structsize;
 dlg.m_ofn.lpstrFilter = "工程文件(*.mpj)\0*.mpj\0所有文件(*.*)\0*.*\0\0";

 if(IDOK == dlg.DoModal())
 {
  CString path = dlg.GetPathName();

  //调用CWinApp::OpenDocumentFile(),将路径传递进去
  CWinApp::OpenDocumentFile(path.GetBuffer(path.GetLength())); 
 }
 
}



转帖:http://wwboss.blog.sohu.com/88957540.html