寻找从我的 C++/MFC 应用程序启用打印的方法
自古以来,我一直试图避免从基于 Windows 的应用程序进行打印,因为缺乏对它的本机支持。每当绝对必要时,我都会动态地制作一个简单的 HTML 布局,然后在 Web 浏览器中打开它,其中包含一个简短的 Java 脚本,为用户弹出一个打印对话框。现在我需要找到更实质性的东西。
让我解释一下。我有一个处理医疗图表的项目,它必须能够打印到这些图表(在特定位置)以及一般打印到 Letter/A4 尺寸的页面。它还必须提供在分页视图环境中打印内容的预览。
鉴于此,我想知道 MFC/C++ 环境(不是 C#)在打印方面可以提供什么?
附言。我正在考虑研究 RTF 格式,但这似乎是一项相当艰巨的任务,所以我也想知道,是否有任何库/已编写的代码可以允许编写/查看/打印 RTF?如果没有,还有什么可以像我上面解释的那样提供打印支持?
Since time immemorial I've been trying to avoid printing from my Windows-based applications due to the lack of native support for it. Whenever absolutely necessary I was resorting to dynamically making a simple HTML layout and then opening it in a web browser with a short Java Script in it to pop up a printing dialog for a user. Now I need to find something more substantial.
Let me explain. I have a project that deals with medical charts and it has to be able to print into those charts (at specific locations) as well as print on to a Letter/A4 size page in general. It also has to provide a preview of what is being printed in a paged-view environment.
In light of that I was wondering what is available from MFC/C++ environment (not C#) in regarding to printing?
PS. I was thinking to look into the RTF format but that seems like quite a daunting task, so I was also wondering, is there any libraries/already written code that can allow to compose/view/print RTFs? If not, what else is out there that can provide printing support like I explained above?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我总是发现从 MFC/C++ 应用程序生成 PDF 文件非常方便,有许多库可以轻松创建 PDF 文件、预览功能等(也是开源的)。我正在使用这个(也处理 RTF):
PDF Library
I always found it very convenient to generate PDF files from my MFC/C++ application, There are many libraries out there which enable easy creation of PDF files, preview functionality and so on (also open source). I'm using this (also handles RTF):
PDF Library
不支持像您使用一些参数调用框架方法,框架为您打印文档或窗口内容。您需要在打印设备上下文上手动绘制所有内容。正如已经说过的,您可能会发现使用 PDF 生成器更方便,但这当然取决于您的应用程序要求。
There is no support like you call a framework method with some parameters and the framework prints a document or the content of a window for you. You need to manually draw everything on the printing device context. So as already said, you might find it more convenient to use a PDF generator, but of course that depends on your application requirements.
请尝试 www.oxetta.com ,它是一个免费的报告生成器解决方案,可以轻松集成到 C/C++ 应用程序中。
Please try www.oxetta.com , it's a free report builder solution that easily integrates into a C/C++ application.
“缺乏原生支持”?它一直被 Petzold 覆盖,并且直接集成到 GDI 中。与 UNIX 相比,这是轻而易举的事情。 MFC 使这一切变得更加容易。
无论如何,这里介绍了如何使用 MFC 进行打印预览,以及以下是 随后的打印方式。那里有很多链接,而且都很简单。打印机只是您可以在其上绘图的另一个设备上下文。
"lack of native support"? It's been covered by Petzold since forever, and it's integrated straight into GDI. Compared to UNIX, it's a complete breeze. And MFC makes it even easier.
Anyway, here's how you do print preview with MFC, and here's how you subsequently print. Lots of links from there, and it's all straightforward. Printers are just another Device Context on which you can draw.