Hello and thanks in advance for reading.
I'm creating a web application that needs some advanced printing capabilities, but since web technologies don't support printing outside of initiating the standard PrintDlg(), I must resort to writing a native windows component.
I'm new to this, but enjoying it very much. So far I've successfully been able to get a list of installed printers using EnumPrinters(), send a string to print using OpenPrinter(), StartDocPrinter(), StartPagePrinter(), WritePrinter(), EndPagePrinter(), EndDocPrinter(), and ClosePrinter() (phew!), and lastly I can grab the public parts of the DevMode structure returned from a call to PrintDlg().
Where I'm stuck is that I need to print more than just a string of text, I need to print the contents of the browser's current page (my web app). I can't simply screenshot it, because the browser renders the page very differently for a printer ("print stylesheets").
So here's my question...
Is it possible to use SendMessage() to tell an external application to print?
I see in Google Chrome's source code that it does handle WM_PRINTCLIENT messages, but it's difficult for me to understand what it's doing. I can successfully grab a handle to it's window and use SendMessage() to WM_CLOSE it, but passing WM_PRINTCLIENT with a printer DC does nothing.
1 2 3 4 5 6
|
LRESULT results = SendMessage(
hWndOwner, //this is a handle to Chrome's window
WM_PRINTCLIENT,
(WPARAM)PrinterContext,
PRF_CLIENT
);
|
Is my understanding of WM_PRINTCLIENT completely wrong? I'm simply sending the message as shown above and hoping that
Chrome will do the printing. Is there some way to retrieve something from that call? MSDN says it's used "most commonly in a printer device context". (
http://msdn.microsoft.com/en-us/library/windows/desktop/dd145217(v=vs.85).aspx)
Your experience is greatly appreciated.