OLECMDID_PRINT和设置打印选项 [英] OLECMDID_PRINT and setting print options

查看:59
本文介绍了OLECMDID_PRINT和设置打印选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++应用程序,允许用户打印多个文档.它使用基于CHTMLView的类,并根据打印请求为每个文档发送一次OLECMDID_PRINT.这可行,但是很粗糙,因为每个文档都会生成一个用户必须与之交互的打印对话框.我想做的是要么抛出一个打印对话框并捕获用户的需求,然后通过我已经在修改的打印模板将其传递给浏览器,要么找到一种方法获取用户对浏览器打印对话框的响应,并将其用于所有后续的OLECMDEXECOPT_DONTPROMTUSER文档.

到目前为止,我发现许多人试图做类似的事情,但没有答案.设置默认打印机不是可接受的选项,因为这会影响所有应用程序.我看不到打印模板中的templateprinter在哪里允许选择打印机,并且找不到从浏览器的打印"对话框捕获任何事件的方法.

我被困住了,有人知道吗?

I have an C++ app that allows the user to print multiple documents. It uses a class based on CHTMLView and on a print request sends a OLECMDID_PRINT once for each document. This works but is crude as each document produces a print dialog that the user has to interact with. What I''d like to do is either throw up a print dialog and capture the user''s desires and pass that along to the browser, maybe via the print template, which I''m already modifying, or find a way to get the user response to the browser''s print dialog and use that for all subsequent docs with OLECMDEXECOPT_DONTPROMTUSER.

So far I''ve found many trying to do similar things but no answers. Setting the default printer isn''t an acceptable option as that will affect all applications. I don''t see where the templateprinter in the print template allows selecting the printer and can find no way to trap any event from the browser''s print dialog.

I''m stuck, anyone have an idea?

推荐答案



我今天只需要在C#中精确地执行此操作即可;).在我的代码中,我必须打印一堆各种格式的文档,我在相关位下面添加了
.
无论如何,我都无法在不更改默认打印机的情况下执行此操作.我只是确保我在必要的时间内更改了默认设置.

这是我的代码:

我派生了WebBrowser控件,并添加了自己的Print方法.

Hi,

I just had to do exactly this in C# today ;). In my code i had to print a bundle of documents in all kind of formats, I''ve added below the relevant bits.

I could not find anyway to do this without changing the default printer. I just made sure I changes the default for as little time as necessary.

Here is my code:

I have derived the WebBrowser control and added my own Print method.

public partial class MyWebBrowser : WebBrowser





public void Print(PrinterSettings ps)
{
    PrinterSettings p = new PrinterSettings();
    string oldPrinter = p.PrinterName;
    SetAsDefaultPrinter(ps.PrinterName);
    this.axIWebBrowser2.ExecWB(OLECMDID.OLECMDID_PRINT,
        OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
        null, IntPtr.Zero);
    SetAsDefaultPrinter(oldPrinter);
}
static int SetAsDefaultPrinter(string printerDevice)
{
    int ret = 0;
    string path = "win32_printer.DeviceId='" + printerDevice + "'";
    using (ManagementObject printer = new ManagementObject(path))
    {
        ManagementBaseObject outParams =
        printer.InvokeMethod("SetDefaultPrinter",null, null);
        ret = (int)(uint)outParams.Properties["ReturnValue"].Value;
    }
    return ret;
}



我这样称呼:



and I call it this way:

PrinterSettings ps = new PrinterSettings();
    PrintDialog p = new PrintDialog();
    if (p.ShowDialog() == DialogResult.OK)
    {
        ps = p.PrinterSettings;
// ...
// a few bits that are not relevant for this example.
// ...

            MyWebBrowser browser = new MyWebBrowser();
            browser.Url = new Uri(document);
            while (browser.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
            browser.Print(ps);

// ...
    }




希望对您有帮助.

瓦莱里.




hope it helps.

Valery.


这篇关于OLECMDID_PRINT和设置打印选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆