Click here to Skip to main content
14,211,070 members
Rate this:
Please Sign up or sign in to vote.
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?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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?

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

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190618.1 | Last Updated 23 Dec 2014
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100