複製鏈接
請複製以下鏈接發送給好友

OpenDocumentFile

鎖定
OpenDocumentFile是以afxwin.h為頭文件的編程名詞。用於框架調用這個成員函數為應用程序打開指定名字的CDocument文件。
外文名
OpenDocumentFile
適用領域
文件編程
功    能
框架調用這個成員函數為應用程序打開指定名字的CDocument文件

OpenDocumentFile

CWinApp ;CDocument; //以CWinApp為例介紹

OpenDocumentFile頭文件

afxwin.h

OpenDocumentFile語法

virtual CDocument*OpenDocumentFile(LPCTSTR lpszFileName); [1] 

OpenDocumentFile參數

要打開的文件的名字

OpenDocumentFile返回值

如果函數調用成功,返回CDocument對象的指針;否則返回零。

OpenDocumentFile説明

如果具有該名字的文檔已經被打開了,則包含這個文檔的第一個框架窗口將被激活。
如果應用程序支持多文檔模板,則框架使用文件擴展名查找適當的文檔模板,試圖載入此文檔。如果成功,則文檔模板為該文檔創建一個框架窗口和視圖。

OpenDocumentFile示例

/****************************************************************
演示函數原型:OpenDocumentFile(mlpCmdLine);
程序功能説明:在文檔中打開指定的文件。
****************************************************************/
//一段例程
//CWinApp派生類CMyApp
class CMyApp: public CWinApp
{  public:  CTestApp( );
CString str;//添加的對話框變量
...  }
//在InitInstance()中調用OpenDocumentFile(mlpCmdLine);
CMyApp *theApp=(CMyApp *)AfxGetApp( );
BOOL CMyApp::InitInstance()
{
//...
//若沒有指定打開文件,則創建一個空文檔
if(mlpCmdLine[0]=='\0')
{//創建一個空文檔
OpenFileNew();
theApp->str=_T("創建一個空文檔");
}
else
{
//打開指定的文件
OpenDocumentFile(mlpCmdLine);
theApp->str=_T("打開指定的文件");
}
//顯示信息
AfxMessageBox(theApp->str);
}
參考資料
  • 1.    MSDN windows高級編程指南