Solved

Creating and Printing a Bitmap from a Dialog

Posted on 1998-07-17
3
253 Views
Last Modified: 2013-11-20
I was handed down a CDialog based program. This program does all sorts of graphing, and just doodles all over the dialog area (using SetPixelV, LineTo, etc). What I want to do is know the most efficient code for extracting a rectangular region of pixels from the dialog area, and spooling them out to the printer so that it fills exactly the entire page no matter what printer I am on.

Example to make myself more clear:
There is a dialog box. There are no controls or buttons or anything on it whatsoever. Some stuff was doodled onto it.
The dialog boxes coordinates are (0,0 to 400,400)
I want to extract a (50,50 to 200,200) rect from the dialog box and send it to the printer in such a way that it always fills one full piece of paper.

How do I accomplish this the best possible way?
Thanks in advance.
0
Comment
Question by:lesinsm
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 30 total points
ID: 1319381
The easieast way is to stretch dialog area giving dialog window HDC directly to printer DC with StrechBlt. The problem can be if dialog area contains color graphics. In this case you should copy dialog area into compatible bitmap selected into memory DC, then convert this memory DDB into 24 bit DIB and only then send this DIB to printer with StretchDIBits. In this case printer will perform the best dithering.
0
 

Author Comment

by:lesinsm
ID: 1319382
How do you convert the memory from DDB into 24-bit DIB?
Thanks, Galkin!
0
 
LVL 7

Expert Comment

by:galkin
ID: 1319383
It is not trivial task. You cannot use any of syetm DIB API since they are dealing with HDC but you cannot use printer DC as b/w printer contains only two colows. so if you try to convert other then two colow bitmap any function will fail. you will have to allocate memory block 3 * height * width bytes in heap with GlobalAlloc, Then lock it with GlobalLock. Then directly set RGB value for each bits in this memory block. handle to this memory is your DIB handle. you can use StretchDIBits to send this DIB to the printer.
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
repeateFront java challenge 31 94
Folder Comparison 12 55
move a line in eclipse 3 107
fix34  challenge 9 148
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 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