MFC中SDI程序創建流程的回顧
SDI程序創建流程的回顧
從CWinApp.InitialInstance()開始,
1.首先應用程序對象創建文檔模板;
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSDICoinDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSDICoinView));
2.文檔模板創建文檔對象、打開或創建文件;
CCommandLineInfo cmdInfo; //處理命令行信息類
enum { FileNew, FileOpen, FilePrint, FilePrintTo, FileDDE,AppUnregister, FileNothing = -1 } nShellCommand; //7種動作類型
CCommandLineInfo::CCommandLineInfo() //CCommandLineInfo類的默認構造函數
{
m_bShowSplash = TRUE;
m_bRunEmbedded = FALSE;
m_bRunAutomated = FALSE;
m_nShellCommand = FileNew;//指定了SHELL命令操作(默認動作)
}
ParseCommandLine(cmdInfo); //根據上面的nShellCommand值,調用CWinApp::ProcessShellCommand()執行相應的動作
FILENEW--->OnFileNew();
FILEOPEN--->OpenDocumentFile();
FilePrint, FilePrintTo--->......
FileDDE--->...
AppUnregister--->...
....
3.文檔模板創建邊框窗口對象和邊框窗口;
4.接着邊框窗口對象創建視對象和視窗口。
下面以FILENEW動作爲例,詳解創建過程:
a.調用文檔模板管理器的成員函數OnFileNew(m_pDocManager->OnFileNew());
b.模板管理器獲取文檔模板對象指針,調用文檔模板對象的OpenDocumentFile 函數(pTemplate->OpenDocumentFile(NULL))。
c.如果模板管理器發現有多個文檔模板,就彈出一個對話框讓用戶選擇文檔模板。
d.CSingleDocTemplate::OpenDocumentFile();
//創建文檔類
CDocument* pDocument = CreateNewDocument();
//創建框架類
CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL);
e.調用CFrameWnd的虛擬函數InitialUpdateFrame完成窗口初始化;
這些創建是以應用程序的文檔模板爲中心進行的。在創建這些MFC對象的同時,建立了它們之間的關係。創建這些之後,進行初始化,激活主邊框窗口,把邊框窗口、視窗口顯示出來。
這樣,一個SDI應用程序就完成了啓動過程,等待着用戶的交互或者輸入。
從CWinApp.InitialInstance()開始,
1.首先應用程序對象創建文檔模板;
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSDICoinDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSDICoinView));
2.文檔模板創建文檔對象、打開或創建文件;
CCommandLineInfo cmdInfo; //處理命令行信息類
enum { FileNew, FileOpen, FilePrint, FilePrintTo, FileDDE,AppUnregister, FileNothing = -1 } nShellCommand; //7種動作類型
CCommandLineInfo::CCommandLineInfo() //CCommandLineInfo類的默認構造函數
{
m_bShowSplash = TRUE;
m_bRunEmbedded = FALSE;
m_bRunAutomated = FALSE;
m_nShellCommand = FileNew;//指定了SHELL命令操作(默認動作)
}
ParseCommandLine(cmdInfo); //根據上面的nShellCommand值,調用CWinApp::ProcessShellCommand()執行相應的動作
FILENEW--->OnFileNew();
FILEOPEN--->OpenDocumentFile();
FilePrint, FilePrintTo--->......
FileDDE--->...
AppUnregister--->...
....
3.文檔模板創建邊框窗口對象和邊框窗口;
4.接着邊框窗口對象創建視對象和視窗口。
下面以FILENEW動作爲例,詳解創建過程:
a.調用文檔模板管理器的成員函數OnFileNew(m_pDocManager->OnFileNew());
b.模板管理器獲取文檔模板對象指針,調用文檔模板對象的OpenDocumentFile 函數(pTemplate->OpenDocumentFile(NULL))。
c.如果模板管理器發現有多個文檔模板,就彈出一個對話框讓用戶選擇文檔模板。
d.CSingleDocTemplate::OpenDocumentFile();
//創建文檔類
CDocument* pDocument = CreateNewDocument();
//創建框架類
CFrameWnd* pFrame = CreateNewFrame(pDocument, NULL);
e.調用CFrameWnd的虛擬函數InitialUpdateFrame完成窗口初始化;
這些創建是以應用程序的文檔模板爲中心進行的。在創建這些MFC對象的同時,建立了它們之間的關係。創建這些之後,進行初始化,激活主邊框窗口,把邊框窗口、視窗口顯示出來。
這樣,一個SDI應用程序就完成了啓動過程,等待着用戶的交互或者輸入。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.