python - 如何知道窗口类名长度?
问题描述
我可以使用此功能获取窗口标题:
import ctypes
from ctypes import wintypes
from collections import namedtuple
user32 = ctypes.WinDLL('user32', use_last_error=True)
def get_title(hWnd, lParam):
pid = wintypes.DWORD()
length = user32.GetWindowTextLengthW(hWnd) + 1
title = ctypes.create_unicode_buffer(length)
user32.GetWindowTextW(hWnd, title, length)
return title.value
我可以使用 user32.GetClassNameW 获取 ClassName,但哪个函数可以替代 GetWindowTextLengthW,它给出 ClassName 的长度?
解决方案
根据WNDCLASSEX的文档,类名最多为 256 个字符,因此您可以给它一个 257 个字符的缓冲区(根据GetClassName为终止符额外增加一个字符)。在处理这么小的缓冲区时,没有必要采取额外的步骤来节省几个字节来获得确切的缓冲区大小。
推荐阅读
- javascript - Cordova 应用程序 - 键盘显示/打开之前的事件侦听器
- c++ - 如何在不设置完整路径的情况下访问 C++ 中的资源
- json - 更新 json 列需要太多时间
- json - 如何捕获 Apache Beam 中的内置转换引发的异常(在本例中为 JSON 解析)
- pandas - Pandas 动态 Groupby 和 Shift
- android - Android警报对话框未从片段内的片段显示
- asp.net-mvc - 我无法在 plesk Dotnet Core Entity Framework 上连接数据库
- docker - 如何在 docker 中调试 odoo?
- mysql - where 子句中的数字如何影响 sunquery
- angular - 如何使我的应用程序可以通过子域访问?