当前位置:网站首页>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
边栏推荐
- Pywin32打开指定窗口
- 网络通信学习
- pytest--之测试报告allure配置
- [tutorial] how to make the Helpviewer help document of VisualStudio run independently
- 传输优化抽象
- 2021-10-02
- MPLS experiment
- VLAN experiment
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
猜你喜欢

AI技术产业热点分析

Solutions to a series of problems in sqoop job creation

Use WinDbg to statically analyze dump files (summary of practical experience)

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer

4.随机变量

【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh

Blender海洋制作

stm32和電機開發(上比特系統)

Feature (5): how to organize information

Pytest framework implements pre post
随机推荐
ERROR 1118 (42000): Row size too large (> 8126)
AI技术产业热点分析
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
12.进程同步与信号量
Pywin32打开指定窗口
STM32 and motor development (upper system)
【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
Shutter - canvas custom graph
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
【避坑指南】Unity3D项目接入腾讯Bugly工具时遇到的坑
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
SPSS做Shapiro-Wilk正态分析
Allure -- common configuration items
[Lua] summary of common knowledge points (including common interview sites)
Blender石头雕刻
判断数组中是否存在重复元素
webUI自动化学习
[MySQL] an exception occurs when connecting to MySQL: connection must be valid and open
Pytest learning --base
pytest学习--base