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. Displaying Bitmaps for Printing

Displaying Bitmaps for Printing

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 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.
  • C Offline
    C Offline
    Chris Klecker
    wrote on last edited by
    #1

    Probably covered. Probably easy. I tried using a CStatic control but ultimately it looked as though it failed. I'm wondering if there is still an easy solution to printing bitmaps from screen to paper or if the solution is convoluted. If it is a difficult solution then might you know where I can find some documentation on the matter? Thanks! Chris "Why are we hiding from the police, Daddy?" "We use VI, son. They use Emacs."

    O 1 Reply Last reply
    0
    • C Chris Klecker

      Probably covered. Probably easy. I tried using a CStatic control but ultimately it looked as though it failed. I'm wondering if there is still an easy solution to printing bitmaps from screen to paper or if the solution is convoluted. If it is a difficult solution then might you know where I can find some documentation on the matter? Thanks! Chris "Why are we hiding from the police, Daddy?" "We use VI, son. They use Emacs."

      O Offline
      O Offline
      Oscar Vazquez
      wrote on last edited by
      #2

      Start a new app from AppWizard, and check "Pinting", this enable print and print preview to your CView. Then draw your bitmap on the OnDraw method of your view. That's all. // PrintTestView.cpp BEGIN_MESSAGE_MAP(CPrintTestView, CView) //{{AFX_MSG_MAP(CPrintTestView) // NOTE - the ClassWizard will add and remove mapping macros here. // DO NOT EDIT what you see in these blocks of generated code! //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() void CPrintTestView::OnDraw(CDC* pDC) { CPrintTestDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CBitmap bmp; if (bmp.LoadBitmap(IDB_BITMAP1)) { // Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); // Create an in-memory DC compatible with the // display DC we're using to paint CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); // Select the bitmap into the in-memory DC CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp); // Find a centerpoint for the bitmap in the client area CRect rect; GetClientRect(&rect); int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2; int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2; // Copy the bits from the in-memory DC into the on- // screen DC to actually do the painting. Use the centerpoint // we computed for the target offset. pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY); dcMemory.SelectObject(pOldBitmap); } } ///////////////////////////////////////////////////////////////////////////// // CPrintTestView printing BOOL CPrintTestView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); }

      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