如何通过GDI Print API实现双面打印

发布于 2025-01-19 16:31:55 字数 742 浏览 4 评论 0原文

我需要在打印机上实现双工打印。 我使用DMDuplex参数设置了打印机驱动程序中的DevMode结构

int dvmSize=DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),NULL,NULL,0);
DEVMODE *dvmSettings = (DEVMODE*) GlobalAlloc(GPTR,dvmSize);
DEVMODE *dvMode = (DEVMODE*) GlobalAlloc(GPTR,dvmSize);
DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),dvmSettings,NULL,DM_OUT_BUFFER);
dvmSettings->dmDuplex=DMDUP_HORIZONTAL;
dvmSettings->dmFields=DM_DUPLEX;
DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),dvMode,dvmSettings,DM_IN_BUFFER|DM_OUT_BUFFER);

据我所知, ,这有2种实现方法。通过WritePrinter或使用CreateC传递DVMode创建HDC并直接绘制到上下文。第二种方法对我来说更方便,但是它会起作用吗?我是因为我现在无法测试它,我需要知道它是否有效。

I need to implement duplex printing on a printer. I set the DEVMODE structure in the printer driver with the dmDuplex parameter

int dvmSize=DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),NULL,NULL,0);
DEVMODE *dvmSettings = (DEVMODE*) GlobalAlloc(GPTR,dvmSize);
DEVMODE *dvMode = (DEVMODE*) GlobalAlloc(GPTR,dvmSize);
DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),dvmSettings,NULL,DM_OUT_BUFFER);
dvmSettings->dmDuplex=DMDUP_HORIZONTAL;
dvmSettings->dmFields=DM_DUPLEX;
DocumentProperties(GetForegroundWindow(),hPrinter,(LPWSTR)(printerName.c_str()),dvMode,dvmSettings,DM_IN_BUFFER|DM_OUT_BUFFER);

As far as I understand, there are 2 ways of implementation. Via WritePrinter or create a HDC using CreateDC passing dvMode and draw directly to the context. The second way is more convenient for me, but will it work? I'm asking because I can't test it right now and I need to know if it will work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我不在是我 2025-01-26 16:31:55

就我而言,它会起作用。

您可以调用 CreateDCPrintDlgEx函数获取打印机DC。

如果您的应用程序调用 CreateDC 函数,它必须提供驱动程序和端口名称。要检索这些名称,请调用 GetPrinterEnumPrinters 函数。

如果您的应用程序调用 PrintDlgEx 函数并在 PRINTDLGEX 结构,系统返回用户选择的打印机的设备上下文句柄。

有关更多详细信息,我建议您可以参考文档:

  1. https://learn.microsoft.com/en-us/windows/win32/printdocs/sending-data-directly-to-a-printer

  2. https://learn.microsoft.com/zh-cn/windows/ win32/printdocs/gdi-打印

  3. https://learn.microsoft.com/en-us/windows/win32/printdocs/printer-output

  4. https://learn.microsoft.com/zh- cn/windows/win32/dlgbox/using-common-dialog-boxes

As far as I'm concerned, it will work.

You could call the CreateDC or PrintDlgEx function to get the printer DC.

If your application calls the CreateDC function, it must supply a driver and port name. To retrieve these names, call the GetPrinter or EnumPrinters function.

If your application calls the PrintDlgEx function and specifies the PD_RETURNDC value in the Flags member of the PRINTDLGEX structure, the system returns a handle to a device context for the printer selected by the user.

For more details I suggest you could refer to the Docs:

  1. https://learn.microsoft.com/en-us/windows/win32/printdocs/sending-data-directly-to-a-printer

  2. https://learn.microsoft.com/zh-cn/windows/win32/printdocs/gdi-printing

  3. https://learn.microsoft.com/en-us/windows/win32/printdocs/printer-output

  4. https://learn.microsoft.com/zh-cn/windows/win32/dlgbox/using-common-dialog-boxes

回忆那么伤 2025-01-26 16:31:55

上面提到的MSDN示例(1)用于将真实的原始数据发送到打印机。

32位和64位过程中GDI位图/DC的像素大小限制是什么?

此示例对我有帮助。它与MSDN示例相似,除了它使用打印机的HDC而不是打印机的句柄。

执行stardoc(pd.hdc)和StartPage(PD.HDC)后,您可以使用pd.hdc绘制GDI命令。它就像getDC()或render_target-&gbegindraw()开头语句,使您可以绘制打印机的直流。执行endPage()和endDoc()就像reparec()或render_target-> endDraw()。

这是一个不相关的问题,这是一个很好的发现,因为试图学习XPS API会导致死端,这是由于某些折衷的功能而导致的,并且没有关于如何将IprintDocument API与XPS API一起使用的好示例。但是,学习如何使用Commandlist使用D2D版本的打印是一项成功的冒险。

The MSDN example mentioned above (1) is for sending real raw data to the printer.

What are pixel size limits of GDI bitmaps/DCs in 32-bit and 64-bit processes?

This example helped me. It's similar steps to the MSDN example except it uses the printer's hdc instead of the printer's handle.

After executing StarDoc(pd.hDC) and StartPage(pd.hDC) you can use the pd.hDC to draw GDI commands. Its like a GetDC() or render_target->BeginDraw() opening statement that allows you to draw on the printer's DC. Executing EndPage() and EndDoc() is like ReleaseDC() or render_target->EndDraw().

This was a good find on stackoverflow for an unrelated question since trying to learn XPS API lead to a dead-end due to some deprecated functions and no good examples on how to use the IPrintDocument API with XPS API. However, learning how to use the D2D version of printing by using the CommandList was a successful venture.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文