Objective Grid: Printing worksheets from CGXTabWnd

Article ID: 314
Last updated: 11 Jun, 2018
Article ID: 314
Last updated: 11 Jun, 2018
Revision: 3
Views: 2006
Posted: 12 Jan, 2001
by Meltreger B.
Updated: 11 Jun, 2018
by Meltreger B.

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);
  1. share the print device object among views by embedding it into your document:
  2. 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?.
 

This article was:   Helpful | Not helpful
Report an issue
Article ID: 314
Last updated: 11 Jun, 2018
Revision: 3
Views: 2006
Posted: 12 Jan, 2001 by Meltreger B.
Updated: 11 Jun, 2018 by Meltreger B.

Others in this category