Click here to Skip to main content
15,887,822 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionThe mismatch between Print preview and the real printing Pin
Member 1388734912-Sep-18 0:47
Member 1388734912-Sep-18 0:47 
AnswerRe: The mismatch between Print preview and the real printing Pin
Richard MacCutchan12-Sep-18 0:57
mveRichard MacCutchan12-Sep-18 0:57 
GeneralRe: The mismatch between Print preview and the real printing Pin
Member 1388734912-Sep-18 2:03
Member 1388734912-Sep-18 2:03 
GeneralRe: The mismatch between Print preview and the real printing Pin
leon de boer12-Sep-18 7:05
leon de boer12-Sep-18 7:05 
GeneralRe: The mismatch between Print preview and the real printing Pin
Member 1388734912-Sep-18 21:07
Member 1388734912-Sep-18 21:07 
GeneralRe: The mismatch between Print preview and the real printing Pin
leon de boer13-Sep-18 0:47
leon de boer13-Sep-18 0:47 
GeneralRe: The mismatch between Print preview and the real printing Pin
Member 1388734913-Sep-18 3:18
Member 1388734913-Sep-18 3:18 
GeneralRe: The mismatch between Print preview and the real printing Pin
leon de boer13-Sep-18 5:29
leon de boer13-Sep-18 5:29 
You aren't getting that memory DC's are basically free you aren't limited to just one and why they exist Smile | :)

Lets see if I can make you understand.

This stuff is only important for bitmaps you can print text all day and never need to know this stuff

1.) When you print bitmaps you make a new memory DC to match the printer not the screen!!!!
HDC SecondDC = CreateCompatibleDC( >>> PrinterDC <<<);
2.) Put your image on the memory DC and you use it to print .. just like you did the screen DC
3.) Now print it.
4.) Now you destroy the memory DC that matches the printer you are done with it.

At no point in that did I change or alter your screen bitmap/DC

What you aren't grasping is why you need a memory DC .. so lets deal with that because it is important.

So a true device DC may have a different planes and colour layout to your image and if that was done
at a driver level, every driver would have to know how to deal with every colour format. So they don't
do that the driver generally knows exactly one colour format usually RGB. The memory context is the
thing that knows all the different formats and is essentially device independent. So when you want to
print what a bitmap what you want is a memory context that matches the PRINTER DC not the screen.

That is all covered here .. I want you to carefully read the paragraph that starts with
"The original bitmap in a memory DC is simply a placeholder"
Memory Device Contexts | Microsoft Docs[^]

Now here is a tutorial on bitmap printing I want you to go to Part 9
https://www.dreamincode.net/forums/topic/261009-bitmap-printing-tutorial-in-c-win32/

I want you to take particular note of lines 9 to 13 which does this
prn = GetPrinterDC(hwnd);
cxpage = GetDeviceCaps (prn, HORZRES);
cypage = GetDeviceCaps (prn, VERTRES);
hdcMem = CreateCompatibleDC(prn);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap);

If you understood the above you will understand what they are doing but lets walk thru it
1.) They got the printer DC because that is our device NOT the screen
2.) They got the width and height of the printer from that DC.
3.) They made a memory DC to the printer DC to transfer the image onto (printer DC not screen DC)
4.) They selected the bitmap you want to print to the memory context so it initializes how
to convert the bitmap for the printer.

Then they will transfer all the image and stuff onto the memory DC, then they will copy it to
the printer and then they will throw the memory context away it isn't needed anymore.

The important part here is the memory context that matches the printer is the right scale
and it has the right colour plane organization and it has nothing to do with your display
memory context which is dangling around elsewhere in your code.
In vino veritas


modified 13-Sep-18 11:47am.

QuestionThread synchronization problem Pin
samzcs10-Sep-18 9:12
samzcs10-Sep-18 9:12 
AnswerRe: Thread synchronization problem Pin
Richard Andrew x6410-Sep-18 9:35
professionalRichard Andrew x6410-Sep-18 9:35 
GeneralRe: Thread synchronization problem Pin
samzcs10-Sep-18 10:09
samzcs10-Sep-18 10:09 
GeneralRe: Thread synchronization problem Pin
Richard Andrew x6410-Sep-18 10:11
professionalRichard Andrew x6410-Sep-18 10:11 
GeneralRe: Thread synchronization problem Pin
samzcs10-Sep-18 10:28
samzcs10-Sep-18 10:28 
QuestionRe: Thread synchronization problem Pin
CPallini10-Sep-18 21:02
mveCPallini10-Sep-18 21:02 
AnswerRe: Thread synchronization problem Pin
samzcs11-Sep-18 2:45
samzcs11-Sep-18 2:45 
GeneralRe: Thread synchronization problem Pin
CPallini11-Sep-18 3:23
mveCPallini11-Sep-18 3:23 
AnswerRe: Thread synchronization problem Pin
leon de boer10-Sep-18 22:08
leon de boer10-Sep-18 22:08 
GeneralRe: Thread synchronization problem Pin
samzcs11-Sep-18 2:50
samzcs11-Sep-18 2:50 
GeneralRe: Thread synchronization problem Pin
leon de boer11-Sep-18 5:05
leon de boer11-Sep-18 5:05 
GeneralRe: Thread synchronization problem Pin
11917640 Member 11-Sep-18 19:53
11917640 Member 11-Sep-18 19:53 
GeneralRe: Thread synchronization problem Pin
samzcs12-Sep-18 8:12
samzcs12-Sep-18 8:12 
GeneralRe: Thread synchronization problem Pin
leon de boer12-Sep-18 18:31
leon de boer12-Sep-18 18:31 
GeneralRe: Thread synchronization problem Pin
11917640 Member 12-Sep-18 18:58
11917640 Member 12-Sep-18 18:58 
AnswerRe: Thread synchronization problem Pin
«_Superman_»23-Sep-18 22:26
professional«_Superman_»23-Sep-18 22:26 
QuestionBreak when address reading Pin
Member 130813699-Sep-18 15:47
Member 130813699-Sep-18 15:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.