Click here to Skip to main content
15,886,732 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to get a image when user print from other applications.
then i hook some api.
first i hooked createdcw and in my hook funciton, i create a memory dc(by CreateCompatibleDC(NULL) ) and return. but the target application show a error.

then, i in my createdcw i create both printer dc(call real createdcw) and a memory dc, and save the memory dc in a map which the key is printer dc. i also create a hbitmap with the with and height same as printer dc(use GetDeviceCaps(hdcPrinter, HORZRES) and GetDeviceCaps(hdcPrinter, VERTRES) ). in my hooked ExtTextOutW(for test, the target application use this function when printing), i get the memory dc by printer dc from the map. and call the real ExtTextOutW to draw the text to memory dc and printer dc.

and at my hooked EndPage function, i save the memory dc to a .bmp file.

but the words in the .bmp file is too small and the character spacing is too large. i think maybe the problem is dpi, memory dc is 96 and the printer dc is 600.

How can i solve this problem?
Posted

1 solution

I encountered the same problem when I writing printer content monitor.
I hooked StartDocW EndDoc StartPage EndPage and hook many GDI APIS (DrawTextExA, FillRect ...)when StartDocW occured.
I tee gdi actions to emf file to get the printer content. It works ok usually, but as same as your problelm, notepad prints result have small character and large character spacing.
Are you fixed this problem now?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900