如何使用 Visual C 在 IE 中的打印模板中将 __IE_PrinterCmd_DevMode 属性设置为 DEVMODE 结构
在用户关闭“打印”对话框后,IE 中的打印模板使用此属性来确定有关所选打印机的信息。如何使用 Visual C++ 中的代码将此属性设置为 DEVMODE 结构。 如何将 DEVMODE 结构转换为变体。如果可能的话,我可以将变量传递给打印模板,然后在 jscript 中设置 __IE_PrinterCmd_DevMode 属性。
The print template in IE uses this property to determine information about the selected printer after a user closes the Print dialog box. How can I set this property to a DEVMODE structure with code in Visual C++.
How can I convert DEVMODE structure to variant. If it possible, I can pass variant to print template and then set __IE_PrinterCmd_DevMode property in jscript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Marc Durdin 有一篇优秀的博客文章,其中包含 Delphi 中的详细示例。它可以轻松移植到 C++ 和其他语言:
特别是,
__IE_PrinterCmd_DevMode
应该是解锁的HGLOBAL
(通常是来自GlobalAlloc
或GlobalReAlloc
)。这在任何地方都没有记录,我猜马克通过反复试验发现了困难的方法,最终发现它与PRINTDLG.hDevMode
和PRINTDLG.hDevNames
字段,如直接通过调用PrintDlg
提供。我已经能够通过
HGLOBAL
作为模板脚本的整数并使用它们来初始化__IE_PrinterCmd_DevMode
和__IE_PrinterCmd_DevNames
,在创建TemplatePrinter
。如果您不想调用ShowHTMLDialogEx
你自己,你已经与你的应用程序挂钩了。我正在使用原始窗口的
external
脚本对象。要从模板访问它,我使用:如果您只想选择系统默认打印机以外的打印机,您也可以设置
__IE_PrinterCMD_Printer
属性。您可以在 JScript 中执行此操作,它将影响TemplatePrinter
设置后创建的行为对象。但是,仅使用此属性,您无法控制初始设置或知道用户最终选择的打印机。
Marc Durdin has an excelent blog post with a detailed example in Delphi. It's easily portable to C++ and other languages:
In particular,
__IE_PrinterCmd_DevMode
should be an unlockedHGLOBAL
(typically a valid return value fromGlobalAlloc
orGlobalReAlloc
). This is not documented anywhere, I guess Marc discovered the hard way by trial and error, finally finding it working with the values in thePRINTDLG.hDevMode
andPRINTDLG.hDevNames
fields, as directly provided by a call toPrintDlg
.I've been able to pass
HGLOBAL
s as integers to a template's script and use them to initialize__IE_PrinterCmd_DevMode
and__IE_PrinterCmd_DevNames
, before creating aTemplatePrinter
. This is handy if you don't want to callShowHTMLDialogEx
yourself and you already have a hook into your application. I'm using the original window'sexternal
scripting object. To access it from the template, I use:If you just want to select a printer other than the system default, you may just as well set the
__IE_PrinterCMD_Printer
property. You can do it in JScript, it'll affect theTemplatePrinter
behavior objects that you create after setting it. However, with this property alone, you cannot control the initial settings or know which printer the user finally chose.我刚刚遇到了同样的问题,并发现 __IE_PrinterCmd_DevMode 和 __IE_PrinterCmd_DevNames 可以从 IntPtr 设置。
这是在 X86 应用程序上,因此不确定在 x64 或 AnyCPU 上会发生什么。
按照建议,我使用一个类通过外部对象传递 DevMode 和 DevNames。
这是代码的主要部分,为此:
然后在打印模板中
I have just had this same issue and have found that __IE_PrinterCmd_DevMode and __IE_PrinterCmd_DevNames can be set from an IntPtr.
This is on a X86 application, so not sure what would happen on x64 or AnyCPU.
As suggested, I use a class to pass in the DevMode and DevNames through the external object.
Here's the main parts of the code, for this:
Then in the Print Template