Solved

Creating and Printing a Bitmap from a Dialog

Posted on 1998-07-17
3
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

626 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