添加支持打印&在基于对话框的MFC应用程序中预览HTML [英] Add support to print & preview HTML in a dialog-based MFC app

查看:238
本文介绍了添加支持打印&在基于对话框的MFC应用程序中预览HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个部分的问题。我需要添加支持打印到现有的基于对话框的MFC项目。正在打印的文档使用HTML组成。我知道我可以添加基于HTML的对话框,但是如何添加一个能力打印呢?

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。我需要这个能够根据程序的需要设置打印页面大小。

PS. I need this to be able to set the print page size according to a program's needs.

推荐答案

http://marc.durdin.net/2011/07/demystifying-printing-with-the-microsoft-webbrowser-control-and-showhtmldialogex-2/ =nofollow>优秀的Marc's Durdin的文章 ,我做了一些更多的spelunking。
实际上似乎更容易提供自定义 DEVMODE DEVNAMES ,并且不使用HTML对话框或自定义 IE打印模板 。反之,应该允许设置自定义打印机,纸张大小,方向等。

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 and DEVNAMES 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.

我在C ++中有一个操场WebBrowser ActiveX主机项目,类似于。我在我的OLE站点对象( IOleClientSite )上实现 IOleCommandTarget 现在这里有趣的部分,当打印调用(通过Ctrl-P或通过 IDM_PRINT ),浏览器控件将 IOleCommandTarget :: Exec(& CGID_DocHostCommandHandler,OLECMDID_PRINT2,& VARIANT(VT_UNKNOWN),NULL) code>。第三个参数包含作为的IUnknown 传递的对象,但查询时的IDispatch 它支持所有相同的<一个HREF =http://msdn.microsoft.com/en-us/library/aa768551%28v=vs.85%29.aspx相对=nofollow> __ IE _ * 属性,可通过 IDispatch :: Invoke 获得:

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 as IOleCommandTarget::Exec(&CGID_DocHostCommandHandler, OLECMDID_PRINT2, &VARIANT(VT_UNKNOWN), NULL). The 3rd parameter contains an object which is passed as IUnknown, but when queried for IDispatch it supports all the same __IE_* properties, available via IDispatch::Invoke:

__IE_TemplateUrl (VT_EMPTY)
__IE_ParentHWND (VT_UINT)
__IE_HeaderString (VT_BSTR)
__IE_FooterString (VT_BSTR)
__IE_OutlookHeader (VT_UNKNOWN)
__IE_BaseLineScale (VT_INT)
__IE_uPrintFlags (VT_UINT)
__IE_ContentDocumentUrl (VT_BSTR)
__IE_ContentSelectionUrl (VT_BSTR)
__IE_PrinterCMD_Printer (VT_BSTR)
__IE_PrinterCMD_Device (VT_BSTR)
__IE_PrinterCMD_Port (VT_BSTR)
__IE_BrowseDocument (VT_UNKNOWN)
__IE_TemporaryFiles (VT_ARRAY)
__IE_PrinterCMD_DevNames (VT_I4)
__IE_PrinterCMD_DevMode (VT_I4)
__IE_PrintType (VT_BSTR)

我没有进一步采取这个,但我认为这应该是可以改变任何人,返回 S_OK IOleCommandTarget :: Exec ,并期望浏览器控件接受更改。

I haven't taken this further yet, but I think it should be possible to alter any of the them and return S_OK from IOleCommandTarget::Exec, and expect the browser control to take in the changes.

我希望它在的 IDM_PRINTPREVIEW /的 OLECMDID_PRINTPREVIEW2 ,但我还没有验证。我会玩这个多一点,时间允许。同时,欢迎您尝试并分享您的结果。

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.

这篇关于添加支持打印&amp;在基于对话框的MFC应用程序中预览HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆