Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating and Printing a Bitmap from a Dialog

Posted on 1998-07-17
3
Medium Priority
?
258 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 90 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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
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.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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