简体   繁体   English

寻找从我的C ++ / MFC应用程序启用打印的方法

[英]Look for ways to enable printing from my C++/MFC application

Since time immemorial I've been trying to avoid printing from my Windows-based applications due to the lack of native support for it. 自远古以来,由于缺乏对本机的支持,我一直试图避免从基于Windows的应用程序中进行打印。 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. 每当绝对必要时,我都会动态制作一个简单的HTML布局,然后在包含简短Java脚本的Web浏览器中打开它,以为用户弹出一个打印对话框。 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. 我有一个处理医学图表的项目,它必须能够打印到那些图表中(在特定位置),并且通常可以打印到Letter / A4尺寸页面上。 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? 有鉴于此,我想知道MFC / C ++环境(非C#)在打印方面有哪些可用?

PS. 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? 我当时正在考虑研究RTF格式,但这似乎是一项艰巨的任务,所以我也想知道,是否有任何库/已编写的代码可以组成/查看/打印RTF? If not, what else is out there that can provide printing support like I explained above? 如果没有,还有什么可以提供打印支持,如我上面解释的那样?

"lack of native support"? “缺乏本地支持”? It's been covered by Petzold since forever, and it's integrated straight into GDI. 它从一开始就被Petzold涵盖,并且直接集成到GDI中。 Compared to UNIX, it's a complete breeze. 与UNIX相比,这是一件轻而易举的事。 And MFC makes it even easier. MFC使它变得更加容易。

Anyway, here's how you do print preview with MFC, and here's how you subsequently print. 总之, 这里是你如何打印预览与MFC,和这里的你如何随后打印。 Lots of links from there, and it's all straightforward. 从那里有很多链接,而且都很简单。 Printers are just another Device Context on which you can draw. 打印机只是可以在其上绘图的另一个设备上下文。

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). 我总是发现从MFC / C ++应用程序生成PDF文件非常方便。那里有许多库,可轻松创建PDF文件,预览功能等(也是开源的)。 I'm using this (also handles RTF): 我正在使用它(也可以处理RTF):

PDF Library PDF资料库

请尝试www.oxetta.com ,这是一个免费的报表生成器解决方案,可以轻松集成到C / C ++应用程序中。

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. 因此,正如已经说过的那样,您可能会发现使用PDF生成器更为方便,但这当然取决于您的应用程序要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM