I have a two-part question. I need to add supporting for printing to an existing dialog-based MFC project. The document being printed is composed using HTML. I know that I can add HTML-based dialog but how do you add a capability for printing to it?
PS. I need this to be able to set the print page size according to a program's needs.
Inspired by the excellent Marc's Durdin's article, I've done some more spelunking. There actually appears to be an easier way to supply custom
DEVMODE
andDEVNAMES
and print without using an HTML dialog or a custom IE print template. That, in turn, should allow to set custom printer, paper size, orientation, etc.I have a playground WebBrowser ActiveX host project in C++, similar to this. I implement
IOleCommandTarget
interface on my OLE site object (IOleClientSite
). Now here's the interesting part, when printing gets invoked (via Ctrl-P or via IDM_PRINT), the browser control calls back the site object asIOleCommandTarget::Exec(&CGID_DocHostCommandHandler, OLECMDID_PRINT2, &VARIANT(VT_UNKNOWN), NULL)
. The 3rd parameter contains an object which is passed asIUnknown
, but when queried forIDispatch
it supports all the same__IE_*
properties, available viaIDispatch::Invoke
:I haven't taken this further yet, but I think it should be possible to alter any of the them and return
S_OK
fromIOleCommandTarget::Exec
, and expect the browser control to take in the changes.I expect it to work in a similar way for IDM_PRINTPREVIEW / OLECMDID_PRINTPREVIEW2, but I haven't verified that yet. I'll play with this a bit more, as time allows. Meanwhile, you're welcome to try it out and share your results.