网友回复
先看看代码:
# -*- enoding:utf-8 -*- # 生成 buffer 对象 import win32con from win32gui import PyMakeBuffer, SendMessage, PyGetBufferAddressAndLen, PyGetString length = 10000 # hWnd=68214这个是句柄值 hWnd=68302 buf = PyMakeBuffer(length) length2 = SendMessage(hWnd, win32con.WM_GETTEXT, length, buf)+1 print(length2) buf = PyMakeBuffer(length2) print('get: ', SendMessage(hWnd, win32con.WM_GETTEXT, length2, buf)) address, length = PyGetBufferAddressAndLen(buf) text = PyGetString(address, length) print('text: ', text)
所使用模块主要是win32gui与win32con
其他窗口操作api
引入模块
import win32gui import win32con import win32api import psutil import win32process
获取当前【鼠标坐标】
# 获取当前鼠标【x y】坐标
point = win32api.GetCursorPos()
通过鼠标坐标 获取鼠标坐标下的【窗口句柄】
# 通过坐标获取坐标下的【窗口句柄】 hwnd = win32gui.WindowFromPoint(x,y) # 请填写 x 和 y 坐标
通过窗口句柄获取 【线程ID 和 进程ID】
# 通过句柄获取【线程ID 进程ID】 hread_id, process_id = win32process.GetWindowThreadProcessId('句柄值')
通过进程ID 获取【进程名称】
# 通过进程ID获取【进程名称】 列:weixin.exe process = psutil.Process('进程ID').name()
通过进程ID 获取【标准路径】
# 通过进程ID 获取主文件程序【标准路径】 列:D:/filed/windoee/weixin.exe p_bin = psutil.Process('进程ID').exe()
通过进程ID 获取当前程序的【CPU利用率...
点击查看剩余70%