여러가지 도큐먼트 타입을 지원시 메뉴, 아이콘, 스트링 리소스 추가
class CDrawApp : public CWinApp
{
...
// Implementation
//{{AFX_MSG(CDrawApp)
afx_msg void OnAppAbout();
afx_msg void OnFileNew();
afx_msg void OnFileNewSelect();
afx_msg void OnFileNewDraw();
afx_msg void OnFileNewText();
afx_msg void OnFileOpen();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// {
private:
int m_nNewDocType;
// }
};
BEGIN_MESSAGE_MAP(CDrawApp, CWinApp)
//{{AFX_MSG_MAP(CDrawApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_NEW_SELECT, OnFileNewSelect)
ON_COMMAND(ID_FILE_NEW_DRAW, OnFileNewDraw)
ON_COMMAND(ID_FILE_NEW_TEXT, OnFileNewText)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
...
END_MESSAGE_MAP()
...
CDrawApp::CDrawApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
m_nNewDocType = 0;
}
BOOL CDrawApp::InitInstance()
{
...
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_DRAWTYPE,
RUNTIME_CLASS(CDrawDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDrawView));
AddDocTemplate(pDocTemplate);
// {
pDocTemplate = new CMultiDocTemplate(
IDR_TEXTTYPE,
RUNTIME_CLASS(CTextDoc),
RUNTIME_CLASS(CTextFrame),
RUNTIME_CLASS(CTextView));
AddDocTemplate(pDocTemplate);
// }
...
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
/*
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
*/
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
...
void CDrawApp::OnFileNew()
{
// TODO: Add your command handler code here
if( !m_nNewDocType )
{
CWinApp::OnFileNew();
}
else
{
POSITION pos = GetFirstDocTemplatePosition( );
CDocTemplate *pTemplate;
for(int i=0 ; i<m_nNewDocType ; i++)
pTemplate = GetNextDocTemplate(pos);
pTemplate->OpenDocumentFile(NULL);
}
}
void CDrawApp::OnFileNewSelect()
{
// TODO: Add your command handler code here
m_nNewDocType = 0; // 타입 지정 안 함
OnFileNew(); // 새 도큐먼트 생성
}
void CDrawApp::OnFileNewDraw()
{
// TODO: Add your command handler code here
m_nNewDocType = 1; // 첫번째 도큐먼트 타입으로…
OnFileNew(); // 새 도큐먼트 생성
}
void CDrawApp::OnFileNewText()
{
// TODO: Add your command handler code here
m_nNewDocType = 2; // 첫번째 도큐먼트 타입으로…
OnFileNew(); // 새 도큐먼트 생성
}
void CDrawApp::OnFileOpen()
{
// TODO: Add your command handler code here
char szFilter[] = "Draw Files(*.drw),Text Files (*.txt) |*.drw;*.txt|All Files(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, szFilter);
if(dlg.DoModal( ) == IDOK)
OpenDocumentFile(dlg.GetPathName());
}