BOOL CApp::InitInstance()
{
///////////////////////////////////
m_pDocTemplate = new CMultiDocTemplate(
IDR_MSG, //user define
RUNTIME_CLASS(MessageDoc),
RUNTIME_CLASS(MessageFrame), // main SDI frame window
RUNTIME_CLASS(MessageView));
AddDocTemplate(m_pDocTemplate);
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
//.....................
............
}
//..........
public:
CMultiDocTemplate * m_pDocTemplate;
//...........
//响应函数 比如按钮
void CApp::OnManageMessage()
{
ASSERT(m_pDocTemplate != NULL);
CDocument* pDoc = NULL;
CFrameWnd* pFrame = NULL;
pDoc = m_pDocTemplate->CreateNewDocument();
if (pDoc != NULL)
{
pFrame = m_pDocTemplate->CreateNewFrame(pDoc, NULL);
if (pFrame != NULL)
{
m_pDocTemplate->SetDefaultTitle(pDoc);
if (!pDoc->OnNewDocument())
{
pFrame->DestroyWindow();
pFrame = NULL;
}
else
m_pDocTemplate->InitialUpdateFrame(pFrame, pDoc, TRUE);
}
else
delete pDoc;
}
if (pFrame == NULL ¦¦ pDoc == NULL)
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
else
.............
}
本文地址:http://com.8s8s.com/it/it3758.htm