internet-explorer - 如何使用 Visual C++ 在 IE 中的打印模板中将 __IE_PrinterCmd_DevMode 属性设置为 DEVMODE 结构

标签 internet-explorer visual-c++ printing dev-mode

在用户关闭“打印”对话框后,IE 中的打印模板使用此属性来确定有关所选打印机的信息。如何使用 Visual C++ 中的代码将此属性设置为 DEVMODE 结构。 如何将 DEVMODE 结构转换为变体。如果可能,我可以将变体传递给打印模板,然后在 jscript 中设置 __IE_PrinterCmd_DevMode 属性。

最佳答案

Marc Durdin 有一篇很棒的博客文章,其中包含一个详细的 Delphi 示例。它很容易移植到 C++ 和其他语言:

Demystifying printing with the Microsoft WebBrowser control and ShowHTMLDialogEx

特别是,__IE_PrinterCmd_DevMode应该是解锁的 HGLOBAL (通常是来自 GlobalAllocGlobalReAlloc 的有效返回值)。这在任何地方都没有记录,我猜 Marc 通过反复试验发现了困难的方法,最终发现它可以使用 PRINTDLG.hDevMode and PRINTDLG.hDevNames 中的值字段,由调用 PrintDlg 直接提供.

我已经能够通过 HGLOBAL s 作为模板脚本的整数并使用它们来初始化 __IE_PrinterCmd_DevMode__IE_PrinterCmd_DevNames , 在创建 TemplatePrinter 之前.如果你不想调用ShowHTMLDialogEx,这很方便。你自己和你已经有一个钩子(Hook)进入你的应用程序。我正在使用原始窗口的 external 脚本对象。要从模板访问它,我使用:

dialogArguments.__IE_BrowseDocument.parentWindow.external

PS: Passing an HGLOBAL as an integer works on a 32-bit process, because JScript's numbers are actually double floats, which can represent sequential integers up to 53-bit. But due to this limitation, passing an HGLOBAL as an integer on a 64-bit process is not reliable.

Maybe you can make your window.external object have a method, which expects a print template's dialogArguments object, that sets the __IE_PrinterCmd_DevMode and __IE_PrinterCmd_DevNames with integer VARIANTs (VT_I8 or VT_UI8).

I haven't tested this yet.

如果您只想选择系统默认打印机以外的打印机,您也可以设置 __IE_PrinterCMD_Printer属性(property)。您可以在 JScript 中执行此操作,它会影响 TemplatePrinter设置后创建的行为对象。但是,仅凭此属性,您无法控制初始设置或知道用户最终选择了哪台打印机。

关于internet-explorer - 如何使用 Visual C++ 在 IE 中的打印模板中将 __IE_PrinterCmd_DevMode 属性设置为 DEVMODE 结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8747463/

相关文章:

c++ - 我该怎么做才能修复 Visual Studio 不显示每个文件属性的问题?

c# - UWP : Print with out Printer Popup Dialoag

javascript - Internet Explorer 中模块的加载超时

javascript - 如何在 IE7 中获取对象元素的 contentWindow

c++ - 如何访问二进制 Mat 图像中的像素值?

printing - 执行方案代码

java - 如何将 BufferedImage 转换为 Printable 以便我可以使用 printJob

javascript - IE 哈希返回按钮的问题

html - CSS 最后一个类型在加载时不匹配

c++ - 使用 Visual C++ for C++ 而不是 C++/CLI