|| | |||Browse by category|
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?
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).
|CGXTabWnd* pTabWnd = GetTabWnd();
BOOL bDirect = FALSE;
for (int n = 0; n < pTabWnd->GetBeam().GetCount(); n++)
|CWnd* pView = (CWnd*) pTabWnd->GetBeam().GetTab(n).pExtra;
bDirect = TRUE;
In your view class, add an attribute
and set this attribute in the view's constructor.
|m_bDirect = FALSE;|
Moreover, add a message handler for ID_FILE_PRINT_DIRECT:
|m_bDirect = TRUE;
m_bDirect = FALSE;
Next, override OnPreparePrinting() as follows:
|BOOL CRepView::OnPreparePrinting(CPrintInfo* pInfo)
|pInfo->m_bDirect = m_bDirect;
// default preparation
To be able to use the same printer settings for all views, the following should work
- 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?.