Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Print a dialog box!

Print a dialog box!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestioncareer
2 Posts 2 Posters 27 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sandrine
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • S 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

      H Offline
      H Offline
      Henk Devos
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups