首先考虑打开对话框。第一步是要弄清,打开对话框是什么时候(在哪)弹出来的?
默认情况下,CDTriNetApp调用CWinApp::OnFileOpen方法处理FileOpen事件:
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
CWinApp::OnFileOpen又调用CDocManager::OnFileOpen处理FileOpen事件:
void CWinApp::OnFileOpen()
{
ENSURE(m_pDocManager != NULL);
m_pDocManager->OnFileOpen();
}
CDocManager::OnFileOpen显示对话框与用户交互,然后调用CWinApp::OpenDocumentFile方法:
void CDocManager::OnFileOpen()
{
// prompt the user (with all document templates)
CString newName;
if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
return; // open cancelled
AfxGetApp()->OpenDocumentFile(newName);
// if returns NULL, the user has already been alerted
}
显然,一种可能的解决办法是绕过CWinApp和CDocManager,在CDTriNetApp::OnFileOpen方法中显示自定义对话框,然后调用CWinApp::OpenDocumentFile方法。
ON_COMMAND(ID_FILE_OPEN, &CDTriNetApp::OnFileOpen)
void CDTriNetApp::OnFileOpen()
{
LPCTSTR szFilter = L"DTriNet文件(*.dtn)|*.dtn|CSV文件(*.csv)|*.csv|所有文件(*.*)|*.*||";
CFileDialog oFileDlg(TRUE, L".dtn", NULL, 4|2, szFilter);
if(oFileDlg.DoModal() == IDOK)
OpenDocumentFile(oFileDlg.GetFileName());
// CDTriNetApp不需要重写CWinApp::OpenDocumentFile方法
默认情况下,CDTriNetApp调用CWinApp::OnFileOpen方法处理FileOpen事件:
ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen)
CWinApp::OnFileOpen又调用CDocManager::OnFileOpen处理FileOpen事件:
void CWinApp::OnFileOpen()
{
ENSURE(m_pDocManager != NULL);
m_pDocManager->OnFileOpen();
}
CDocManager::OnFileOpen显示对话框与用户交互,然后调用CWinApp::OpenDocumentFile方法:
void CDocManager::OnFileOpen()
{
// prompt the user (with all document templates)
CString newName;
if (!DoPromptFileName(newName, AFX_IDS_OPENFILE,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
return; // open cancelled
AfxGetApp()->OpenDocumentFile(newName);
// if returns NULL, the user has already been alerted
}
显然,一种可能的解决办法是绕过CWinApp和CDocManager,在CDTriNetApp::OnFileOpen方法中显示自定义对话框,然后调用CWinApp::OpenDocumentFile方法。
ON_COMMAND(ID_FILE_OPEN, &CDTriNetApp::OnFileOpen)
void CDTriNetApp::OnFileOpen()
{
LPCTSTR szFilter = L"DTriNet文件(*.dtn)|*.dtn|CSV文件(*.csv)|*.csv|所有文件(*.*)|*.*||";
CFileDialog oFileDlg(TRUE, L".dtn", NULL, 4|2, szFilter);
if(oFileDlg.DoModal() == IDOK)
OpenDocumentFile(oFileDlg.GetFileName());
// CDTriNetApp不需要重写CWinApp::OpenDocumentFile方法
}
参考网址:http://wenku.baidu.com/link?url=J_Kg16rEobIoeSvxmdPsNMFrKKMhNvRTYbYZNE2vu2eLwN48SYEw5i5PDgXAUY4Uuip7uT-iN-Xp7JyZ2CGnZAthcUXc9PvOSJrWzX5AAvC