Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Marc Durdin has an excelent blog post with a detailed example in Delphi. It's easily portable to C++ and other languages:</p> <blockquote> <p><a href="http://marc.durdin.net/2011/07/demystifying-printing-with-microsoft.html" rel="nofollow">Demystifying printing with the Microsoft WebBrowser control and ShowHTMLDialogEx</a></p> </blockquote> <p>In particular, <a href="http://msdn.microsoft.com/en-us/library/aa753352.aspx" rel="nofollow"><code>__IE_PrinterCmd_DevMode</code></a> should be an unlocked <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751.aspx" rel="nofollow"><code>HGLOBAL</code></a> (typically a valid return value from <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366574.aspx" rel="nofollow"><code>GlobalAlloc</code></a> or <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa366590.aspx" rel="nofollow"><code>GlobalReAlloc</code></a>). This is not documented anywhere, I guess Marc discovered the hard way by trial and error, finally finding it working with the values in the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646843.aspx" rel="nofollow"><code>PRINTDLG.hDevMode</code> and <code>PRINTDLG.hDevNames</code></a> fields, as directly provided by a call to <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms646940.aspx" rel="nofollow"><code>PrintDlg</code></a>.</p> <p>I've been able to pass <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751.aspx" rel="nofollow"><code>HGLOBAL</code></a>s as integers to a template's script and use them to initialize <a href="http://msdn.microsoft.com/en-us/library/aa753352.aspx" rel="nofollow"><code>__IE_PrinterCmd_DevMode</code></a> and <a href="http://msdn.microsoft.com/en-us/library/aa753353.aspx" rel="nofollow"><code>__IE_PrinterCmd_DevNames</code></a>, before creating a <a href="http://msdn.microsoft.com/en-us/library/aa969431.aspx" rel="nofollow"><code>TemplatePrinter</code></a>. This is handy if you don't want to call <a href="http://msdn.microsoft.com/en-us/library/aa741859.aspx" rel="nofollow"><code>ShowHTMLDialogEx</code></a> yourself and you already have a hook into your application. I'm using the original window's <code>external</code> scripting object. To access it from the template, I use:</p> <pre><code>dialogArguments.__IE_BrowseDocument.parentWindow.external </code></pre> <blockquote> <p>PS: Passing an <code>HGLOBAL</code> 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 <code>HGLOBAL</code> as an integer on a 64-bit process is not reliable.</p> <p>Maybe you can make your <code>window.external</code> object have a method, which expects a print template's <code>dialogArguments</code> object, that sets the <code>__IE_PrinterCmd_DevMode</code> and <code>__IE_PrinterCmd_DevNames</code> with integer <code>VARIANT</code>s (<code>VT_I8</code> or <code>VT_UI8</code>).</p> <p>I haven't tested this yet.</p> </blockquote> <p>If you just want to select a printer other than the system default, you may just as well set the <a href="http://msdn.microsoft.com/en-us/library/aa753351.aspx" rel="nofollow"><code>__IE_PrinterCMD_Printer</code></a> property. You can do it in JScript, it'll affect the <a href="http://msdn.microsoft.com/en-us/library/aa969431.aspx" rel="nofollow"><code>TemplatePrinter</code></a> 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload