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. printing with MFC

printing with MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 5 Posters 0 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.
  • V Offline
    V Offline
    vikas amin
    wrote on last edited by
    #1

    Pls dont send me any link i have gone through them , I have an MFC Application . My problem is simple that i have a document from which in need to print . but when i print the font size change gets small which is also visisble in the printpriview . is there any simple way by which i can have the same printout as it is visible in the frame window thanx Vikas Amin Embin Technology Bombay

    L D P R 4 Replies Last reply
    0
    • V vikas amin

      Pls dont send me any link i have gone through them , I have an MFC Application . My problem is simple that i have a document from which in need to print . but when i print the font size change gets small which is also visisble in the printpriview . is there any simple way by which i can have the same printout as it is visible in the frame window thanx Vikas Amin Embin Technology Bombay

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Show the code. Or try this, from MSDN :

      // get the default printer
      CPrintDialog dlg(FALSE);
      dlg.GetDefaults();

      // is a default printer set up?
      HDC hdcPrinter = dlg.GetPrinterDC();
      if (hdcPrinter == NULL)
      {
      MessageBox(_T("Buy a printer!"));
      }
      else
      {
      // create a CDC and attach it to the default printer
      CDC dcPrinter;
      dcPrinter.Attach(hdcPrinter);

      // call StartDoc() to begin printing
      DOCINFO docinfo;
      memset(&docinfo, 0, sizeof(docinfo));
      docinfo.cbSize = sizeof(docinfo);
      docinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");

      // if it fails, complain and exit gracefully
      if (dcPrinter.StartDoc(&docinfo) < 0)
      {
      MessageBox(_T("Printer wouldn't initalize"));
      }
      else
      {
      // start a page
      if (dcPrinter.StartPage() < 0)
      {
      MessageBox(_T("Could not start page"));
      dcPrinter.AbortDoc();
      }
      else
      {
      // actually do some printing
      CGdiObject* pOldFont = dcPrinter.SelectStockObject(SYSTEM_FONT);

           dcPrinter.TextOut(50, 50, \_T("Code Project Rulezz"), 12);
      
           dcPrinter.EndPage();
           dcPrinter.EndDoc();
           dcPrinter.SelectObject(pOldFont);
        }
      

      }
      }


      "Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
      -- modified at 8:58 Monday 6th February, 2006

      1 Reply Last reply
      0
      • V vikas amin

        Pls dont send me any link i have gone through them , I have an MFC Application . My problem is simple that i have a document from which in need to print . but when i print the font size change gets small which is also visisble in the printpriview . is there any simple way by which i can have the same printout as it is visible in the frame window thanx Vikas Amin Embin Technology Bombay

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        In your view's OnPrepareDC() method, play around with SetMapMode(), SetWindowOrg(), SetViewportOrg(), SetWindowExt(), and SetViewportExt(). I might have left a sample in the code for this article.


        "The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli

        1 Reply Last reply
        0
        • V vikas amin

          Pls dont send me any link i have gone through them , I have an MFC Application . My problem is simple that i have a document from which in need to print . but when i print the font size change gets small which is also visisble in the printpriview . is there any simple way by which i can have the same printout as it is visible in the frame window thanx Vikas Amin Embin Technology Bombay

          P Offline
          P Offline
          PJ Arends
          wrote on last edited by
          #4

          How are you creating your font for printing? You can use CreatPointFont(), passing in the printer DC which will account for the higher DPI of the printer as compared to the screen. Or you could use CreateFontIndirect() and calculating the LOGFONT.lfHeight variable depending on the DPI of the printer

          logfont.lfHeight = -MulDiv(PointSize, PrinterDC.GetDeviceCaps(LOGPIXELSY), 72);
          MyCFont.CreateFontIndirect(&logfont);

          I can't recall where I got the MulDiv formula from, but I am sure it is in MSDN somewhere.


          "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ???  You're definitely a superstar!!!" - mYkel - 21 Jun '04 "There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05 Within you lies the power for good - Use it!

          1 Reply Last reply
          0
          • V vikas amin

            Pls dont send me any link i have gone through them , I have an MFC Application . My problem is simple that i have a document from which in need to print . but when i print the font size change gets small which is also visisble in the printpriview . is there any simple way by which i can have the same printout as it is visible in the frame window thanx Vikas Amin Embin Technology Bombay

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

            I'm having the same problem. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            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