ShellExecute,“打印" [英] ShellExecute, "Print"

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

问题描述

我通过 C 使用 ShellExecute,除了一个问题外,这似乎工作正常.

I am using ShellExecute through C and that seem's work OK except one issue.

ShellExecute(NULL, "print", "C:\\index.html", NULL, NULL, SW_HIDE);

有了这个,我想获得打印对话框以按 OK 开始打印,但不是打开 MS Word 并加载文件 C:\index.html.

With this I would like to get print dialog for press OK for start printing but instead of that MS Word opens with file C:\index.html loaded.

如何使用 ShellExecute 在 html 文件上获得打印功能?

How to get print functionality on html files with ShellExecute?

需要注意的是,IE 不是我的默认互联网浏览器.

If is important to note, IE is not my default internet browser.

推荐答案

您依赖 shell 的关联来打印文件,但这是一种非常脆弱的方法.如果您右键单击该文件并选择打印,您将观察到与调用 ShellExecute 相同的行为.

You are relying on the shell's associations to print the file, but that's a terribly brittle approach. If you right click on the file and select Print you'll observe the same behaviour as your call to ShellExecute.

因此,如果您想将 ShellExecutePrint 动词一起使用,您将需要更改机器的配置.您需要确保机器的关联配置为以适合您的方式处理 .html 文件上的 Print 动词.你可以在你的机器上这样做,但你不能指望在其他人的机器上这样做.

So, if you want to use ShellExecute with the Print verb you will need to change your machine's configuration. You need to make sure that the machine's associations are configured to handle the Print verb on a .html file in a way that suits you. You could do that for your machine but you cannot expect to do it for other people's machines.

相反,您可以运行此命令以确保将打印 HTML 文件:

Instead you could run this command to be sure that the HTML file will be printed:

rundll32.exe %windir%\system32\mshtml.dll,PrintHTML "C:\index.html"

您可以轻松地将其转换为 ShellExecute 调用.

You can translate that readily into a ShellExecute call.

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

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