当前位置:网站首页>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项目接入腾讯Bugly工具时遇到的坑
- [pit avoidance guide] pit encountered by unity3d project when accessing Tencent bugly tool
- Lunix reallocates root and home space memory
- Retrofit's callback hell is really vulnerable in kotlin synergy mode!
- 【Unity3D】无法正确获取RectTransform的属性值导致计算出错
- 快速做出原型
- ue4材质的入门和原理笔记
- Blender stone carving
- Flink实时计算topN热榜
- Introduction and Principle notes of UE4 material
猜你喜欢

allure--常用配置项

Edge computing accelerates live video scenes: clearer, smoother, and more real-time
![[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened](/img/c3/aec0a9fb79cf94b3575d95530aa8e8.png)
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened

Flutter——Canvas自定义曲线图

Considerations for Apache deploying static web page projects

对话吴纲:我为什么笃信“大国品牌”的崛起?

Flink submitter

Flink calculates topn hot list in real time

Introduction and Principle notes of UE4 material

Unreal material editor foundation - how to connect a basic material
随机推荐
Nonlinear optimization: steepest descent method, Newton method, Gauss Newton method, Levenberg Marquardt method
Sum the two numbers to find the target value
Considerations for Apache deploying static web page projects
Blender体积雾
Webui automated learning
pytest框架实现前后置
虚幻材质编辑器基础——如何连接一个最基本的材质
MYSQL环境配置
Operator-1初识Operator
2021-09-12
Vscode auto format
flume 190 INSTALL
虛幻AI藍圖基礎筆記(萬字整理)
[unity3d] nested use layout group to make scroll view with dynamic sub object height
AI技术产业热点分析
01 install virtual machine
Blender摄像机环绕运动、动画渲染、视频合成
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
[tutorial] how to make the Helpviewer help document of VisualStudio run independently
数据库字典Navicat自动生成版本