当前位置:网站首页>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
边栏推荐
- What is the significance of the college entrance examination
- Windows环境MySQL8忘记密码文件解决方案
- [unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
- Pywin32打开指定窗口
- SQOOP 1.4.6 INSTALL
- [visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
- SAP Spartacus express checkout design
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- [Fantasy 4] introduction and use of UMG components (under update...)
- flume 190 INSTALL
猜你喜欢
SUS系统可用性量表
2021-10-02
Flink实时计算topN热榜
Flink submitter
【MySQL】连接MySQL时出现异常:Connection must be valid and open
Stm32 et développement de moteurs (système supérieur)
【Unity3D】嵌套使用Layout Group制作拥有动态子物体高度的Scroll View
Considerations for Apache deploying static web page projects
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
This article takes you to learn in detail what is fiber to home FTTH
随机推荐
【leetcode】33. Search rotation sort array
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
js setTimeout()与面试题
stm32和電機開發(上比特系統)
Introduction and Principle notes of UE4 material
【MySQL】连接MySQL时出现异常:Connection must be valid and open
Operator-1初识Operator
shell编程01_Shell基础
Considerations for Apache deploying static web page projects
[IDL] Research
【避坑指南】使用UGUI遇到的坑:Text组件无法首行缩进两格
618再次霸榜的秘密何在?耐克最新财报给出答案
对话吴纲:我为什么笃信“大国品牌”的崛起?
Application of rxjs operator withlatestfrom in Spartacus UI of SAP e-commerce cloud
12.进程同步与信号量
Blender stone carving
13.信号量临界区保护
[Fantasy 4] the transformation from U3D to UE4
Allure -- common configuration items
2021-09-12