如何隐藏从Python调度的COM对象 [英] How to hide COM object Dispatched from Python

查看:87
本文介绍了如何隐藏从Python调度的COM对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Python中使用COM,并且希望对象在后​​台运行-隐藏。
使用Excel,我这样做:

I'm using COM in Python and I want the object to run in background - hidden. With Excel I do:

Import win32com.client 
Excel=win32com.client.Dispatch("Excel.Application") 
Excel.Visible=1

但我的应用程序没有属性。可见-还有其他隐藏方法吗?

but my application do not have property .Visible - is there any other way to hide it? Maybe some special parameter to Dispatch?

预先感谢
R

Thanks in advance R

推荐答案

如果您知道应用程序的标题或类,则可以通过ShowWindow将其隐藏:

If you know your application title or class, you can hide it via ShowWindow:

import win32com.client 
import win32con
import win32gui
import time

print "Start"
excel = win32com.client.Dispatch("Excel.Application") 
excel.Visible = 1   # Visible via automation
time.sleep(2)
hwnd = win32gui.FindWindow(None, "Microsoft Excel")  # Class or title
print "Hide"
win32gui.ShowWindow(hwnd, win32con.SW_HIDE) # Hide via Win32Api
time.sleep(2)
print "Show"
win32gui.ShowWindow(hwnd, win32con.SW_SHOW) # Show via Win32Api
time.sleep(2)

###

HTH,
巴勃罗

HTH, Pablo

这篇关于如何隐藏从Python调度的COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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