Solved

HOW DO I PRINT THE SCREEN ?

Posted on 2000-05-02
7
261 Views
Last Modified: 2013-11-20
HELLO,
  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?? ?
0
Comment
Question by:mkjoshi
  • 4
  • 2
7 Comments
 

Accepted Solution

by:
raschalk earned 15 total points
ID: 2769629
Hi,

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.


--Rudy
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2769669
Programmatic or ?
0
 

Expert Comment

by:raschalk
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.

--Rudy
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 

Author Comment

by:mkjoshi
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.
0
 

Author Comment

by:mkjoshi
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.


0
 

Expert Comment

by:raschalk
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



SUMMARY
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.



MORE INFORMATION
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;
PrintDC.Attach(dlg.m_pd.hDC);

// ADD YOUR CODE HERE.

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

 
0
 

Expert Comment

by:raschalk
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
dog bark java program 15 112
Thin secure Windows 10 5 102
Increment column based of a FK 8 32
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 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