Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python win32api.ShellExecute()函数的作用是什么?_Python_Winapi_Printing - Fatal编程技术网

Python win32api.ShellExecute()函数的作用是什么?

Python win32api.ShellExecute()函数的作用是什么?,python,winapi,printing,Python,Winapi,Printing,我正在学习用python打印文件。我找到了很多方法,其中一种最常见的方法就是使用win32api模块 import win32api win32api.ShellExecute(0, "print", path_for_file , None, ".", 0) 当我运行这个程序时,文件打印没有任何问题 但问题是,我不了解win32api.ShellExecute()函数中的实际情况以及它的参数的函数是什么。通过arumings,我的意思是:(0,“打印”

我正在学习用python打印文件。我找到了很多方法,其中一种最常见的方法就是使用
win32api
模块

import win32api
win32api.ShellExecute(0, "print", path_for_file , None, ".", 0)
当我运行这个程序时,文件打印没有任何问题

但问题是,我不了解
win32api.ShellExecute()
函数中的实际情况以及它的参数的函数是什么。通过arumings,我的意思是:
(0,“打印”,路径为文件,无,“.”,0)

有人能解释一下
win32api.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

简而言之,这执行的操作与在Windows资源管理器中右键单击文件的路径,然后从关联菜单中选择打印相同。与文件类型关联的应用程序使用
print
动词和
SW_HIDE
show命令执行,这通常意味着它将以静默方式打印文档,而不显示任何UI。

您是否在查找相应的winapi文档?正如我所说的,如果您不知道什么是窗口所有权,并且它对对话框有影响,那么您将无法得到这种格式的答案。你需要做一些研究。也就是说,你的打印方法非常脆弱,你最不关心的是父窗口句柄。嗨,谢谢你的解释,但我不理解第一、第四和第五个参数的用法。请您更详细地解释一下三个参数的功能好吗?@Lenovo360第一次见(tl;dr最常
NULL
)。对于第四种情况,如果您使用
ShellExecute
来运行可执行文件,而不是通过关联来运行谓词,那么这些参数将在命令行上传递给目标可执行文件(启动文档文件时不适用)。有关shell对象和动词的更多信息,例如。。。。对于第5个,它用于设置目标进程的路径,在那里传递完整路径将允许
path to file
使用相对路径。但是,在您的示例中,
是当前工作目录,因此它与传递
NULL
具有相同的效果。