开发者

How to hide COM object Dispatched from Python

开发者 https://www.devze.com 2023-01-30 17:40 出处:网络
I\'m using COM in Python and I want the object to run in background - hidden. With Excel I do: Import win32com.client

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

Import win32com.client 
Excel=开发者_如何学JAVAwin32com.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?

Thanks in advance R


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, Pablo

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号