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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Print Related issue

Print Related issue

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
8 Posts 3 Posters 1 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.
  • R Offline
    R Offline
    rajeevktripathi
    wrote on last edited by
    #1

    Hi I have a dilog based application, what I want is to print the contents of edit box of dialog. I know that CPrintDialog pops the print dialog of windows , but not sure how to move further, ( How to print Edit Zox Context.) So please help me. Thanks

    G H 2 Replies Last reply
    0
    • R rajeevktripathi

      Hi I have a dilog based application, what I want is to print the contents of edit box of dialog. I know that CPrintDialog pops the print dialog of windows , but not sure how to move further, ( How to print Edit Zox Context.) So please help me. Thanks

      G Offline
      G Offline
      Ganesh_T
      wrote on last edited by
      #2

      Check this out: You can save the text into file and then pass that file for printing http://www.codersource.net/mfc_print_tutorial_1.html Cheers "Peace of mind through Technology"

      R 1 Reply Last reply
      0
      • G Ganesh_T

        Check this out: You can save the text into file and then pass that file for printing http://www.codersource.net/mfc_print_tutorial_1.html Cheers "Peace of mind through Technology"

        R Offline
        R Offline
        rajeevktripathi
        wrote on last edited by
        #3

        Hi Thanks for your reply, Infact I dont a dialog and want to print Edit Box content without saving it to a file. Please reply. Thanks

        1 Reply Last reply
        0
        • R rajeevktripathi

          Hi I have a dilog based application, what I want is to print the contents of edit box of dialog. I know that CPrintDialog pops the print dialog of windows , but not sure how to move further, ( How to print Edit Zox Context.) So please help me. Thanks

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          you can use like this(my suggestion) PRINTDLG printdlg; DOCINFO docinfo; ... ... PrintDlg(&printdlg); printdlg.cbSize = sizeof(DOCINFO); printdlg.lpszDocName = "Job"; printdlg.lpszOutput = NULL; StartDoc (printdlg.hDC, &docinfo); StartPage (printdlg.hDC); TextOut (printdlg.hDC,10,10,"This is a sample",16); EndPage (printdlg.hDC); EndDoc (printdlg.hDC);_**


          **_

          whitesky


          R 1 Reply Last reply
          0
          • H Hamid Taebi

            you can use like this(my suggestion) PRINTDLG printdlg; DOCINFO docinfo; ... ... PrintDlg(&printdlg); printdlg.cbSize = sizeof(DOCINFO); printdlg.lpszDocName = "Job"; printdlg.lpszOutput = NULL; StartDoc (printdlg.hDC, &docinfo); StartPage (printdlg.hDC); TextOut (printdlg.hDC,10,10,"This is a sample",16); EndPage (printdlg.hDC); EndDoc (printdlg.hDC);_**


            **_

            whitesky


            R Offline
            R Offline
            rajeevktripathi
            wrote on last edited by
            #5

            HI googled and studied about printing and now able to print a string buffer. the code is as follows: void CPrint_DialogDlg::OnPrintReport() { char pbuf[100] = "Hello World."; HDC hdcPrn ; // Instantiate a CPrintDialog. CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL); // Initialize some of the fields in PRINTDLG structure. printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1; printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1; // Display Windows print dialog box. printDlg->DoModal(); // Obtain a handle to the device context. hdcPrn = printDlg->GetPrinterDC(); if (hdcPrn != NULL) { CDC *pDC = new CDC; pDC->Attach (hdcPrn); // attach a printer DC pDC->StartDoc("test"); // begin a new print job // for Win32 use // CDC::StartDoc(LPDOCINFO) override pDC->StartPage(); // begin a new page SetPrintAlign(pDC, hdcPrn);// set the printing alignment pDC->TextOut(10, 10, pbuf);// write the string in pbuf pDC->EndPage(); // end a page pDC->EndDoc(); // end a print job pDC->Detach(); // detach the printer DC delete pDC; } delete printDlg; } void CPrint_DialogDlg::SetPrintAlign(CDC *pDC, HDC hdcPrn) { short cxPage, cyPage; cxPage = ::GetDeviceCaps (hdcPrn, HORZRES) ; cyPage = ::GetDeviceCaps (hdcPrn, VERTRES) ; pDC->SetMapMode (MM_ISOTROPIC) ; pDC->SetWindowExt ( 1000, 1000) ; pDC->SetViewportExt (cxPage / 2, -cyPage / 2) ; pDC->SetViewportOrg (cxPage / 2, cyPage / 2) ; pDC->SetTextAlign (TA_BASELINE | TA_CENTER) ; } Now here What I want to ask is that : How can I handle if buffer content is of more than one page. Better if provide some code snippet. Thanks in advance.

            H 1 Reply Last reply
            0
            • R rajeevktripathi

              HI googled and studied about printing and now able to print a string buffer. the code is as follows: void CPrint_DialogDlg::OnPrintReport() { char pbuf[100] = "Hello World."; HDC hdcPrn ; // Instantiate a CPrintDialog. CPrintDialog *printDlg = new CPrintDialog(FALSE, PD_ALLPAGES | PD_RETURNDC, NULL); // Initialize some of the fields in PRINTDLG structure. printDlg->m_pd.nMinPage = printDlg->m_pd.nMaxPage = 1; printDlg->m_pd.nFromPage = printDlg->m_pd.nToPage = 1; // Display Windows print dialog box. printDlg->DoModal(); // Obtain a handle to the device context. hdcPrn = printDlg->GetPrinterDC(); if (hdcPrn != NULL) { CDC *pDC = new CDC; pDC->Attach (hdcPrn); // attach a printer DC pDC->StartDoc("test"); // begin a new print job // for Win32 use // CDC::StartDoc(LPDOCINFO) override pDC->StartPage(); // begin a new page SetPrintAlign(pDC, hdcPrn);// set the printing alignment pDC->TextOut(10, 10, pbuf);// write the string in pbuf pDC->EndPage(); // end a page pDC->EndDoc(); // end a print job pDC->Detach(); // detach the printer DC delete pDC; } delete printDlg; } void CPrint_DialogDlg::SetPrintAlign(CDC *pDC, HDC hdcPrn) { short cxPage, cyPage; cxPage = ::GetDeviceCaps (hdcPrn, HORZRES) ; cyPage = ::GetDeviceCaps (hdcPrn, VERTRES) ; pDC->SetMapMode (MM_ISOTROPIC) ; pDC->SetWindowExt ( 1000, 1000) ; pDC->SetViewportExt (cxPage / 2, -cyPage / 2) ; pDC->SetViewportOrg (cxPage / 2, cyPage / 2) ; pDC->SetTextAlign (TA_BASELINE | TA_CENTER) ; } Now here What I want to ask is that : How can I handle if buffer content is of more than one page. Better if provide some code snippet. Thanks in advance.

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              you need to one StartDoc and EndDoc and use StartPage EndPage for another pages StartDoc (pd.hDC, &di); StartPage (pd.hDC); TextOut(pd.hDC,10,10,"This is a sample",16); EndPage (pd.hDC); StartPage (pd.hDC); TextOut(pd.hDC,10,10,"This is a sample",16); EndPage (pd.hDC); EndDoc (pd.hDC);_**


              **_

              whitesky


              R 1 Reply Last reply
              0
              • H Hamid Taebi

                you need to one StartDoc and EndDoc and use StartPage EndPage for another pages StartDoc (pd.hDC, &di); StartPage (pd.hDC); TextOut(pd.hDC,10,10,"This is a sample",16); EndPage (pd.hDC); StartPage (pd.hDC); TextOut(pd.hDC,10,10,"This is a sample",16); EndPage (pd.hDC); EndDoc (pd.hDC);_**


                **_

                whitesky


                R Offline
                R Offline
                rajeevktripathi
                wrote on last edited by
                #7

                Thanks WhiteSky for your replies. Now problem that I am facing is: in TextOut() method if I have to pass a buffer which consists of some new line (\n) and tab ( \t) characters then this prints ||| for these characters. So please tell me that how can I handle this problem i.e. when I want to print something in new line. Thanks

                H 1 Reply Last reply
                0
                • R rajeevktripathi

                  Thanks WhiteSky for your replies. Now problem that I am facing is: in TextOut() method if I have to pass a buffer which consists of some new line (\n) and tab ( \t) characters then this prints ||| for these characters. So please tell me that how can I handle this problem i.e. when I want to print something in new line. Thanks

                  H Offline
                  H Offline
                  Hamid Taebi
                  wrote on last edited by
                  #8

                  it worked for me CString str="Is this a Test \n 123 \n yes it is \n 456"; StartDoc (pd.hDC, &di); StartPage (pd.hDC); DrawText(pd.hDC,str,str.GetLength(),CRect(0,0,1500,350),DT_EXTERNALLEADING); EndPage (pd.hDC); EndDoc (pd.hDC);_**


                  **_

                  whitesky


                  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