Posted on 2000-05-02
Last Modified: 2013-11-20
  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?? ?
Question by:mkjoshi
  • 4
  • 2

Accepted Solution

raschalk earned 15 total points
ID: 2769629

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.


Expert Comment

ID: 2769669
Programmatic or ?

Expert Comment

ID: 2770520
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.

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 2776111
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.

Author Comment

ID: 2776114
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.


Expert Comment

ID: 2777374
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


Expert Comment

ID: 2777458
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.

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now