• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:


  I have displayed some pics on the screen which need to be printed out. The print option prints blank sheet, How do I make the screen get printed?? ?
  • 4
  • 2
1 Solution

Try this:

1. Hold the Alt key down and press the "PrintScreen" button.( next to F12 key usually)
2.Open a Word or wordpad document.
3. Hold the shift key down and press "insert" key to paste the pic into the document.
4. Use Word or WordPad to print out the images to the printer.

Programmatic or ?
Not Programmatic.

If you want to do it from within your code, you need to describe the problem a little better.

1. I have displayed some pics on the screen which need to be printed out.

Q1-- How are you displaying pics on the screen ?
Q2-- What type of application are you building? (Doc-View, Dialog, etc)
Q3-- Have you tried to implement a solution that is not working in your code? If so, which Classes, methods are you using? What is the specific failure mode?

If you add some details about your problem, Im sure you will get a solution quickly from the many knowlegeable MFC programmers here.

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

mkjoshiAuthor Commented:
OK, Let me start,
  I am displaying a set of rectangular boxes using CClientDC.Draw3dRect(...)
and some circles on those rectangles
using CClientDC.Ellipse(...)
It's not a dialog
It's a Doc-View application.

Hope you got it now.
Thanks for the questions.
mkjoshiAuthor Commented:
HI Rudy,
Your solution seems OK but I want to print the screen when 'print'option is selected on the mainframe.

1. Hold the Alt key down and press the "PrintScreen" button.( next to F12 key usually)
2.Open a Word or wordpad document.
3. Hold the shift key down and press "insert" key to paste the pic into the document.
4. Use Word or WordPad to print out the images to the printer.

Hi Mkjoshi,
Hope this helps:

How To Create a Printer Device Context (DC) in MFC
Last reviewed: July 31, 1997
Article ID: Q162609  
1.52 2.00 2.10 2.20 4.00 4.10 4.20 WINDOWS NT kbprint kbcode kbhowto
The information in this article applies to:

The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++ for Windows, 16-bit Edition, version 1.52 - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1, 2.2, 4.0,

     4.1, 4.2

When you create a printer device context (DC) in Windows SDK programming, an application must retrieve ::CreateDC()'s parameters (such as driver name, device name and output port) from either a Win.ini file (16-bit) or a Windows registry (32-bit). In Microsoft Foundation Classes, this can be done via a call to functions CWinApp::GetPrinterDeviceDefaults() and CPrintDialog::CreatePrinterDC().

This article shows you a way to create a printer device context using the default selected printer without displaying the Print dialog box. To create a printer device context for a non-default printer, please refer to Chapter 15 of "Programming Windows 3.1" by Charles Petzold.

The CWinApp::GetPrinterDeviceDefaults() expects a PRINTDLG structure to be passed in such a way that the data retrieved can be stored in the DEVMODE and DEVNAMES handles of the structure. Those data are then used to create a printer DC in the CPrintDialog::CreatePrinterDC() function.

Since CreatePrinterDC() and m_pd (a PRITNDLG variable) are member function and member variable of the CPrintDialog class, a CPrintDialog variable is defined and used in the following sample code.

Sample Code

// Instantiate a CPrintDialog object.
CPrintDialog dlg(FALSE);

// Retrieve the current printer defaults from the Windows .ini file
// as necessary, or uses the last printer configuration set by the
// user in Print Setup.
CWinApp* app = AfxGetApp(); if (!app->GetPrinterDeviceDefaults(&dlg.m_pd))
    // Fails to create a printer device context for printing because
    // no printer is being installed. Bring up dialog box to alert the
    // users that they need to install a printer.  This step is optional.
    if (app->DoPrintDialog(&dlg) != IDOK)
       return ;

// Creates a printer DC from the DEVMODE and DEVNAMES structures.
if (dlg.CreatePrinterDC() == NULL)
    return ;

// A printer device context (DC) has been created.
// Attach it to a CDC object. The DC is deleted when the CDC
// object goes out of scope.
CDC PrintDC;


"Programming Windows 3.1," Charles Petzold, Chapter 15, Microsoft Press, 1992

Hi mkjoshi,

Here is a nice description of how to implement print functionality more suited for Doc/View architecture: This is also from MSDN:

If you have access to MSDN search for "Moving Your Printing Code to MFC"
There is a nice flowchart which is worth a thousand words. The text of the article is below:

Moving Your Printing Code to MFC

CView::OnDraw has a second very important purpose in MFC besides housing your painting code. The framework implements both printing and print preview using your view's OnDraw function. The basic idea is that in MFC you simply draw to the current device — sometimes it's the display, sometimes it's a printer, and sometimes it's a printer emulation on the display (print preview).

Because of this, the File Print command is mapped to class CView, which does all of the necessary setup work and then calls OnDraw to render the image using the device context object passed to it. For drawing on the display, the CDC pointer passed is for the display. For drawing on a printer, the CDC is for the current printer. And for drawing a scaled image in a print preview window, the CDC that is passed wraps two device contexts. One represents the display; the other represents the printer. Using both device contexts, drawing output in OnDraw emulates printer output in the print preview window to approximate the output you could expect to see on the printer.

When you move your printing code into OnDraw, you get to abandon much of it. MFC takes care of displaying File Print and File Print Setup dialog boxes. It also manages the print loop in large measure. Most of what you keep is the actual GDI code that renders the image on the printer.

As shown in Figure 12, when it's time to print a page, MFC calls your view's OnPrepareDC and OnPrint member functions, passing the number of the page to print (page counts start at 1). OnPrepareDC makes adjustments to the device context before drawing takes place. OnPrint calls OnDraw, passing along its device context pointer, and OnDraw draws the current page. For simple printing, all of this takes place with no intervention from you. But if you are doing multiple-page printing, printing headers and/or footers, and the like, you'll need to override OnPrepareDC and/or OnPrint.

If you need to make your own adjustments to the device context before printing a page, override OnPrepareDC in your view class. You might, for instance, move the viewport origin and the clipping region to ensure that the appropriate portion of the document gets printed. For multiple-page documents, this is how you set up to print specified pages, placing the viewport origin at the calculated upper left corner of the page within your document.

Override OnPrint to perform any rendering that should be done only during printing and not for screen display. For example, you can draw headers and footers in OnPrint before (and after) OnDraw renders the rest of the page.

If your application is not WYSIWYG ("What you see is what you get") — that is, if what you print differs significantly from what you display on the screen — you can separate the print-only logic from the display logic in OnDraw, perhaps like this:

.... if (IsPrinting) // another CView member function { // Do print-only drawing } else // Do display drawing }

Or you can do all of your print-only drawing in your OnPrint override without calling OnDraw from there. In this way, OnDraw is called only for screen display, while OnPrint is called only for printing and print preview.

SHOWDIB's printing logic (not shown in this guide or the samples) is necessarily separate from its screen display logic, so you would avoid calling OnDraw from OnPrint. This is because you display a bitmap on screen all at once, but you print it in "bands" or strips. Screen display is handled in OnDraw, while printing is handled in OnPrint. This is the exceptional case in which the two processes cannot be independent of the device being used. Fortunately, a fair amount of the printing code (involving dialog boxes and some parts of the printing loop) disappears under MFC due to all of the things the framework does for you.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now