Print a dialog box!
-
Hi! In my MDI app, i want to add a "Print" button at each dialog box to allow to the user to print it. Is it possible to print a dialog box? I try to use the CWnd::Print() function. The help says "Call this member function to draw the current window in the specified device context, which is most commonly in a printer device context." But it doesn't work! This is my code... void CSACellDefDlg::OnPrint() { CDC dc; CPrintDialog printDlg(FALSE); // Get printer settings from user if (printDlg.DoModal() == IDCANCEL) return; // Attach a printer DC dc.Attach(printDlg.GetPrinterDC()); dc.m_bPrinting = TRUE; // Get the application title and initialise print document details DOCINFO di; ::ZeroMemory (&di, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = ""; // Begin a new print job BOOL bPrintingOK = dc.StartDoc(&di); // Get the printing extents and store in the m_rectDraw field of a // CPrintInfo object CPrintInfo Info; Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES)); // begin new page dc.StartPage(); this->Print(&dc,PRF_ERASEBKGND); // end page bPrintingOK = (dc.EndPage() > 0); if (bPrintingOK) // end a print job dc.EndDoc(); else // abort job. dc.AbortDoc(); // detach the printer DC dc.Detach(); } Thanks for your help Sandrine
-
Hi! In my MDI app, i want to add a "Print" button at each dialog box to allow to the user to print it. Is it possible to print a dialog box? I try to use the CWnd::Print() function. The help says "Call this member function to draw the current window in the specified device context, which is most commonly in a printer device context." But it doesn't work! This is my code... void CSACellDefDlg::OnPrint() { CDC dc; CPrintDialog printDlg(FALSE); // Get printer settings from user if (printDlg.DoModal() == IDCANCEL) return; // Attach a printer DC dc.Attach(printDlg.GetPrinterDC()); dc.m_bPrinting = TRUE; // Get the application title and initialise print document details DOCINFO di; ::ZeroMemory (&di, sizeof (DOCINFO)); di.cbSize = sizeof (DOCINFO); di.lpszDocName = ""; // Begin a new print job BOOL bPrintingOK = dc.StartDoc(&di); // Get the printing extents and store in the m_rectDraw field of a // CPrintInfo object CPrintInfo Info; Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES)); // begin new page dc.StartPage(); this->Print(&dc,PRF_ERASEBKGND); // end page bPrintingOK = (dc.EndPage() > 0); if (bPrintingOK) // end a print job dc.EndDoc(); else // abort job. dc.AbortDoc(); // detach the printer DC dc.Detach(); } Thanks for your help Sandrine
Did you try giving your dialogs a WM_PRINTCLIENT message handler? And shouldn't you add the flag PRF_PRINTCLIENT? ================== The original message was:
Hi!In my MDI app, i want to add a "Print" button at each dialog box to allow to the user to print it.
Is it possible to print a dialog box?I try to use the CWnd::Print() function. The help says "Call this member function to draw the current window in the specified device
context, which is most commonly in a printer device context."But it doesn't work!
This is my code...
void CSACellDefDlg::OnPrint()
{
CDC dc;CPrintDialog printDlg(FALSE);
// Get printer settings from user
if (printDlg.DoModal() == IDCANCEL)
return;// Attach a printer DC
dc.Attach(printDlg.GetPrinterDC());
dc.m_bPrinting = TRUE;// Get the application title and initialise print document details
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = "";// Begin a new print job
BOOL bPrintingOK = dc.StartDoc(&di);// Get the printing extents and store in the m_rectDraw field of a
// CPrintInfo object
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0,dc.GetDeviceCaps(HORZRES),dc.GetDeviceCaps(VERTRES));// begin new page
dc.StartPage();this->Print(&dc,PRF_ERASEBKGND);
// end page
bPrintingOK = (dc.EndPage() > 0);if (bPrintingOK)
// end a print job
dc.EndDoc();
else
// abort job.
dc.AbortDoc();// detach the printer DC
dc.Detach();
}Thanks for your help
Sandrine