Len*_*360 5 python printing winapi
我正在学习如何用 python 打印文件。我发现了很多方法可以做到这一点,我见过的最常见的方法之一是使用该win32api
模块。
import win32api
win32api.ShellExecute(0, "print", path_for_file , None, ".", 0)
Run Code Online (Sandbox Code Playgroud)
当我运行这个程序时,文件被打印出来,没有任何问题。
但问题是我不明白函数中实际发生了什么win32api.ShellExecute()
以及它的参数的函数是什么。通过参数,我的意思是:(0, "print", path_for_file , None, ".", 0)
谁能解释一下win32api.ShellExecute()
函数中的每个参数的作用吗?
如果有人能帮助我,那就太好了。
基于ShellExecute文档:
ShellExecute(0, // NULL since it's not associated with a window
"print", // execute the "print" verb defined for the file type
path_for_file, // path to the document file to print
None, // no parameters, since the target is a document file
".", // current directory, same as NULL here
0) // SW_HIDE passed to app associated with the file type
Run Code Online (Sandbox Code Playgroud)
简而言之,这与path_for_file
在 Windows 资源管理器中右键单击文档,然后print
从上下文菜单中进行选择执行的操作相同。print
与文件类型关联的应用程序使用动词和show 命令执行SW_HIDE
,这通常意味着它将静默打印文档,而不显示任何 UI。