分类: C/C++
2008-08-01 16:52:42
CAttendanceDlg dlg;之后立即把这个对象的指针信息存入CWinApp::m_pMainWnd 和附加的m_pMiddle中备用:
m_pMainWnd = &dlg; m_pMiddle = &dlg;2.在ClassWizard中为主对话框类导入OnCreate()函数,在其中创建子框架对象CChildFrame
CChildFrame* pFrame = new CChildFrame; m_pChildFrame = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,//,m_pMainWnd NULL);暂时将其显示状态置为隐藏: m_pChildFrame->ShowWindow(SW_HIDE);
CCreateContext context; context.m_pNewViewClass = RUNTIME_CLASS(CChildView); context.m_pCurrentFrame = this; context.m_pCurrentDoc = NULL; context.m_pLastView = NULL; m_pView = STATIC_DOWNCAST(CChildView, CreateView(&context)); //CreateView(&context); if(m_pView != NULL) { m_pView->ShowWindow(SW_HIDE);//暂时将其显示状态也置为隐藏 SetActiveView(m_pView); }4.在主对话框的打印或打印预览处理函数中只要向子框架CChildFrame发送相应的消息即可: 对于打印函数为:
m_pChildFrame->SendMessage(WM_COMMAND, ID_FILE_PRINT);或对于打印预览函数为:
m_pChildFrame->ShowWindow(SW_SHOW);//将子框架CChildFrame显示状态置为显示 m_pChildFrame->SendMessage(WM_COMMAND, ID_FILE_PRINT_PREVIEW);//打印预览5.在子框架CChildFrame的打印预览处理函数中需要将CWinApp::m_pMainWnd暂时替换为子框架CChildFrame的指针,并把子视类对象的显示状态激活后调用子视类对象的打印预览处理函数
CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); app->m_pMainWnd = this;//应用程序主窗口临时替换为子框架窗口 m_pView->ShowWindow(SW_SHOW); SetActiveView(m_pView); m_pView->OnFilePrintPreview(this);6.打印预览结束退出之前必须恢复原有的显示状态,并将CWinApp::m_pMainWnd恢复为主对话框:
pParent->ShowWindow(SW_HIDE);//将子框架CChildFrame显示状态重新置为隐藏 pParent->UpdateWindow(); CAttendanceApp* app=(CAttendanceApp*)AfxGetApp(); app->m_pMainWnd = app->m_pMiddle;//应用程序主窗口恢复为主对话框窗口 app->m_pMiddle->UpdateWindow();这些后处理工作放在CWrapperView::OnEndPrintPreview(..)函数中的结尾处完成。