在用户关闭“打印”对话框后,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
(通常是来自 GlobalAlloc
或 GlobalReAlloc
的有效返回值)。这在任何地方都没有记录,我猜 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 anHGLOBAL
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'sdialogArguments
object, that sets the__IE_PrinterCmd_DevMode
and__IE_PrinterCmd_DevNames
with integerVARIANT
s (VT_I8
orVT_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/