当前位置:网站首页>Pywin32 opens the specified window
Pywin32 opens the specified window
2022-07-02 10:41:00 【Snail speed is updating】
def open_app():
try:
win32api.ShellExecute(0, 'open', self.app_path, '', '', 1)
except:
print(f'Program can not be opened...')
def get_windows(windowsname, filename):
# Get window handle
handle = win32gui.FindWindow(None, os.path.basename(windowsname).split('.')[0])
# Judge whether the application is opened , If it doesn't open , Not open handle by 0
if handle == 0:
print(' Program not open '.center(50, '='))
open_app(windowsname)
time.sleep(2)
# app After opening , Back to the handle assignment
handle = win32gui.FindWindow(None, os.path.basename(windowsname).split('.')[0])
# When applying minimize , Use this instruction to maximize the application again --> This statement is very important
win32gui.ShowWindow(handle, win32con.SW_MAXIMIZE)
## Put the window on the front desk , And activate the window ( Windows cannot be minimized )
win32gui.SetForegroundWindow(handle)
time.sleep(1)
# Get the window DC
hdDC = win32gui.GetWindowDC(handle)
# Create a... Based on the handle DC
newhdDC = win32ui.CreateDCFromHandle(hdDC)
# Create a compatible device memory DC
saveDC = newhdDC.CreateCompatibleDC()
# establish bitmap Save the picture
saveBitmap = win32ui.CreateBitmap()
# Get window location information
left, top, right, bottom = win32gui.GetWindowRect(handle)
# Window length and width
width = right - left
height = bottom - top
# bitmap initialization
saveBitmap.CreateCompatibleBitmap(newhdDC, width, height)
saveDC.SelectObject(saveBitmap)
saveDC.BitBlt((0, 0), (width, height), newhdDC, (0, 0), win32con.SRCCOPY)
saveBitmap.SaveBitmapFile(saveDC, filename)
get_windows(r"C:\Users\Administrator\Desktop\PyWin32.chm", " Screenshot .png")
explain , Refer to the code of other big men on the network , When writing an article , No connection found , Please forgive me , Changes have been made to the code , It mainly solves the problem of calling the window , The program doesn't exist , Or the program is currently minimized , Return to the desktop from the minimized state , For reference only
边栏推荐
- shell编程01_Shell基础
- Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
- Metaclass type and using metaclass to implement model class ORM
- Basic notes of illusory AI blueprint (10000 words)
- Transport Optimization abstraction
- [MySQL] an exception occurs when connecting to MySQL: connection must be valid and open
- Flink calculates topn hot list in real time
- 大华设备播放过程中设置播放速度
- VLAN experiment
- 01安装虚拟机
猜你喜欢
随机推荐
sqoop创建job出现的一系列问题解决方法
session-cookie与token
[Fantasy 4] the transformation from U3D to UE4
ERROR 1118 (42000): Row size too large (> 8126)
Message mechanism -- getting to know messages and message queues for the first time
Flutter——Canvas自定义曲线图
[jetbrain rider] an exception occurred in the construction project: the imported project "d:\visualstudio2017\ide\msbuild\15.0\bin\roslyn\microsoft.csh" was not found
01安装虚拟机
axis设备的rtsp setup头中的url不能带参
【MySQL】连接MySQL时出现异常:Connection must be valid and open
[unity3d] nested use layout group to make scroll view with dynamic sub object height
MYSQL环境配置
pytest学习--base
【leetcode】33. Search rotation sort array
Mock Server基本使用方法
13.信号量临界区保护
合并有序数列
Solution of mysql8 forgetting password file in Windows Environment
flume 190 INSTALL
SQOOP 1.4.6 INSTALL









