fff.huoqujubing() hwnd = win32gui.FindWindow(None, "【魔域】") print(hwnd) controls = [] win32gui.EnumChildWindows(hwnd, lambda hwnd, param: param.append(hwnd), controls) for control in controls: title = win32gui.GetWindowText(control) 将获取的 内容保存为TXT
时间: 2024-03-13 13:45:09 浏览: 147
好的,以下是将获取的内容保存为txt文件的Python代码示例:
```python
import win32gui
# 获取窗口句柄
hwnd = win32gui.FindWindow(None, "【魔域】")
# 枚举窗口所有子控件
controls = []
win32gui.EnumChildWindows(hwnd, lambda hwnd, param: param.append(hwnd), controls)
# 遍历所有子控件并获取文本
text = ""
for control in controls:
title = win32gui.GetWindowText(control)
if title:
text += title + "\n"
# 将文本保存为txt文件
with open("output.txt", "w") as f:
f.write(text)
print("保存成功!")
```
以上代码会将获取到的所有子控件的文本保存为一个名为`output.txt`的文本文件。您可以根据实际需求修改代码中的窗口标题和保存文件名。
相关问题
hwnd = win32gui.FindWindow("WeChatMainWndForPC", None) 没获取到
在使用 `win32gui.FindWindow()` 函数查找窗口时,你需要确保传入的窗口类名和窗口名参数都正确。如果你使用的是中文语言的微信客户端,可能窗口类名和窗口名是中文的,你需要传入正确的中文字符串。
以下是一个使用 `win32gui.FindWindow()` 函数查找中文窗口的示例:
```python
import win32gui
# 查找中文窗口
hwnd = win32gui.FindWindow("WeChatMainWndForPC", "微信")
if hwnd:
print("找到了微信窗口,句柄为:{}".format(hwnd))
else:
print("未找到微信窗口")
```
在上面的例子中,我们将窗口类名设置为 `"WeChatMainWndForPC"`,窗口名设置为 `"微信"`。如果找到了符合条件的窗口,`FindWindow()` 函数将返回窗口的句柄,否则返回 0。你可以根据需要修改窗口类名和窗口名的字符串。
vscode python判断窗口是否最大化hriin = win32gui.FindWindow(None,"未命名-1 - RIIN")
在VSCode中直接检查Python脚本是否能通过win32gui库来检测Windows窗口是否最大化并非其核心功能,因为VSCode是一个集成开发环境,而win32gui主要是用于系统级别的API调用,通常用于自动化测试或编写Windows GUI程序。
如果你想要在Python中操作窗口状态,比如判断一个窗口是否最大化,你需要导入`ctypes`和`windll.user32`模块,然后利用`FindWindow`函数找到对应的窗口句柄,再使用`GetWindowPlacement`或`IsZoomed`等函数获取窗口信息。例如:
```python
import ctypes
from ctypes.wintypes import DWORD
user32 = ctypes.windll.user32
# 找到窗口句柄
hwnd = user32.FindWindowW(None, "未命名-1 - RIIN")
if hwnd != 0: # 如果找到了窗口
placement = user32.GetWindowPlacement(hwnd)
is_maximized = placement[1] == 2 # 判断窗口是否最大化,值为2表示最大化
print(f"窗口{'已最大化' if is_maximized else '未最大化'}")
else:
print("窗口未找到")
阅读全文
相关推荐
















