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

查看:18
本文介绍了添加对打印和在基于对话框的 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.

推荐答案

灵感来自 Marc 的 Durdin 的优秀文章,我做了更多的探索.实际上似乎有一种更简单的方法来提供自定义 DEVMODEDEVNAMES 并在不使用 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++ 中的 Playground WebBrowser ActiveX 宿主项目,类似于 this.我在我的 OLE 站点对象 (IOleClientSite) 上实现了 IOleCommandTarget 接口.现在这是有趣的部分,当调用打印时(通过 Ctrl-P 或通过 IDM_PRINT),浏览器控件将站点对象回调为 IOleCommandTarget::Exec(&CGID_DocHostCommandHandler, OLECMDID_PRINT2, &VARIANT(VT_UNKNOWN), NULL).第三个参数包含一个作为 IUnknown 传递的对象,但是当查询 IDispatch 时,它支持所有相同的 __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)

我还没有更进一步,但我认为应该可以更改其中的任何一个并从 IOleCommandTarget::Exec 返回 S_OK,并期望浏览器控件接受更改.

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.

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

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