让对话框也支持多文档的使用
【打印文章】
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
.............
}
{
///////////////////////////////////
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
.............
}
本栏文章均来自于互联网,版权归原作者和各发布网站所有,本站收集这些文章仅供学习参考之用。任何人都不能将这些文章用于商业或者其他目的。( Pfan.cn )
【编程爱好者论坛】