| | | | Browse by category |
Problem
I would like my users to be able to print all worksheets in my CGXTabWnd with one command. The print dialog should only be displayed for the first view. How can I do this?
Cause
Action
In your view class (or any other class) implement a function that loops through all worksheets and sends an ID_FILE_PRINTDIRECT message to all worksheets (the best way is to 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; |
|||
} | |||
} |
In your view class, add an attribute
BOOL m_bDirect; |
and set this attribute in the view's constructor.
m_bDirect = FALSE; |
Moreover, add a message handler for ID_FILE_PRINT_DIRECT:
void CRepView::OnFilePrintDirect() { |
||
m_bDirect = TRUE; OnFilePrint(); m_bDirect = FALSE; |
||
} |
Next, 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
CGXPrintDevice m_pd; |
GetParam()->SetPrintDevice(&GetDocument()->m_pd, FALSE); CGXGridView::SetPrintDevice(&GetDocument()->m_pd, FALSE); |
- share the print device object among views by embedding it into your document:
- In OnInitialUpdate(), add the following lines:
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 entitled How can I use CGXPrintDevice with scroll views or other views not derived from CGXView?.