I would like my users to be able to print all worksheets in my CGXTabWnd with one command. The print dialog should be only displayed for the first view. How can I do this?
In your view class (or any other class) implement a function that loops through all worksheets and sends a ID_FILE_PRINTDIRECT message to all worksheets (the best is you make a menu entry for this message).
void CRepView::PrintEntireWorkbook()
{
CGXTabWnd* pTabWnd = GetTabWnd();
BOOL bDirect = FALSE;
for (int n = 0; n < pTabWnd->GetBeam().GetCount(); n++)
{
CWnd* pView = (CWnd*) pTabWnd->GetBeam().GetTab(n).pExtra;
pView->SendMessage(WM_COMMAND, bDirect?ID_FILE_PRINT_DIRECT:ID_FILE_PRINT);
bDirect = TRUE;
}
}
and in your view add an attribute
BOOL m_bDirect;
in constructor set this attribute
m_bDirect = FALSE;
Moreover, add a message handler for ID_FILE_PRINT_DIRECT:
void CRepView::OnFilePrintDirect()
{
m_bDirect = TRUE;
OnFilePrint();
m_bDirect = FALSE;
}
Next you override OnPreparePrinting as follows:
BOOL CRepView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->m_bDirect = m_bDirect;
// default preparation
return DoPreparePrinting(pInfo);
}
To be able to use the same printer settings for all views, the following should work
a) share the print device object among views by embedding it into your document:
CGXPrintDevice m_pd;
b) In OnitialUpdate add the following lines
GetParam()->SetPrintDevice(&GetDocument()->m_pd, FALSE);
CGXGridView::SetPrintDevice(&GetDocument()->m_pd, FALSE);
For views that are not derived from CGXGridView, you don't need to call GetParam()->SetPrintDevice, but you should take a look at the FAQ "How can I use CGXPrintDevice with Scrollview or other views not derived from CGXView? ".