在學習一MDI檔案程式時,在訊息映射表中發現選單項中的“打開檔案“事件映射到CWinApp::OnFileOpen事件,而不是我想象的自定義打開檔案事件。
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
在源檔案里也沒有找到CWinApp::OnFileOpen的回傳值。
百度后發現CWinApp::OnFileOpen原型在appdlg.cpp中,于是設好斷點,程式也順利的跟蹤到 ENSURE(m_pDocManager != NULL);
m_pDocManager->OnFileOpen();
逐程序跟蹤,來到cmdtarg.cpp中的 AFX_STATIC BOOL AFXAPI _AfxDispatchCmdMsg函式中,應該是訊息分發把,跟蹤到(pTarget->*mmf.pfnCmd_v_v)(); break;
不知道這個是什么玩意,百度后就知道是指向什么函式指標,沒搞明白,之后就是一些訊息路由之類的,在跟下去就是會到 “未加載的wuser32,pdb界面“,最后還是不知道獲取的檔案名是如何回傳的,奇怪的是程式并沒有中斷,點幾下“跳出”跟蹤按鈕程式能正常執行,可以看到子視窗已經加載了指定的檔案了。
其實中間的程序我只想搞個大致明白就行了,問題是CWinApp::OnFileOpen的回傳值什么時候得到的,如何處理的?
uj5u.com熱心網友回復:
添加自定義回應函式 OnMyFileOpenON_COMMAND(ID_FILE_OPEN, CMyWinApp::OnMyFileOpen)
uj5u.com熱心網友回復:
我知道可以添加自定義程序,我是想問CWinApp::OnFileOpen的回傳值什么時候得到的,如何處理的?uj5u.com熱心網友回復:
CWinApp::OnFileOpen has a very simple implementation of calling CWinApp::DoPromptFileName followed by CWinApp::OpenDocumentFile with the file or path name of the file to open. The CWinApp implementation routine DoPromptFileName brings up the standard FileOpen dialog and fills it with the file extensions obtained from the current document templates.uj5u.com熱心網友回復:
pTarget->*mmf.pfnCmd_v_v)()這個嘛,就是呼叫函式指標,這個指標指向OnFileOpen,ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen) 本質就是將ID_FILE_OPEN 這個命令和CWinApp::OnFileOpen關聯起來
uj5u.com熱心網友回復:
通過 class CRecentFileList可以 得到 成功打開過 的 檔案名
uj5u.com熱心網友回復:
即theApp.m_pRecentFileList->m_arrNames[j]
uj5u.com熱心網友回復:
想得到打開的檔案名, 多載 App類的 OpenDocumentFile, 傳進來的引數就是 打開的檔案名CDocument* CMyApp::OpenDocumentFile(LPCTSTR lpszFileName)
{
// TODO: Add your specialized code here and/or call the base class
return CWinApp::OpenDocumentFile(lpszFileName);
}
uj5u.com熱心網友回復:
7樓正解,多載 App類的 OpenDocumentFile轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/67091.html
標籤:基礎類
