当前位置:网站首页>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
边栏推荐
- [unity3d] production progress bar - make image have the functions of filled and sliced at the same time
- Network communication learning
- pytest学习--base
- Introduction and Principle notes of UE4 material
- SQOOP 1.4.6 INSTALL
- [tutorial] how to make the Helpviewer help document of VisualStudio run independently
- [leetcode] sword finger offer 53 - I. find the number I in the sorted array
- 【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
- flume 190 INSTALL
- Flink submitter
猜你喜欢
![[Fantasy 4] introduction and use of UMG components (under update...)](/img/33/7e3b74192b7fd73d5145f85e061d1f.png)
[Fantasy 4] introduction and use of UMG components (under update...)

【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格

Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?

VLAN experiment

互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书

pytest--之测试报告allure配置

stm32和电机开发(上位系统)

Flutter环境配置保姆级教程,让doctor一绿到底

Is this code PHP MySQL redundant?

Blender model import UE, collision settings
随机推荐
[tutorial] how to make the Helpviewer help document of VisualStudio run independently
Merge ordered sequence
大华设备播放过程中设置播放速度
Considerations for Apache deploying static web page projects
【教程】如何让VisualStudio的HelpViewer帮助文档独立运行
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
Network communication learning
pytest学习--base
pytest--之测试报告allure配置
MYSQL关键字
Pywin32打开指定窗口
Rapid prototyping
webUI自动化学习
虛幻AI藍圖基礎筆記(萬字整理)
14.信号量的代码实现
使用sqlcipher打开加密的sqlite方法
Redis set password
ERROR 1118 (42000): Row size too large (> 8126)
Delivery mode design of Spartacus UI of SAP e-commerce cloud
flume 190 INSTALL