Solved

Creating and Printing a Bitmap from a Dialog

Posted on 1998-07-17
3
247 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
GIF file bit manipulation for color change 5 104
iSeries FTP Exit Program 8 114
bigDiff challenge 17 75
Problem to open Excel file 15 44
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

9 Experts available now in Live!

Get 1:1 Help Now