windll.user32.GetWindowLongPtrW(hwnd, self.GWL_EXSTYLE) 这段代码在我的系统上报错。我在使用win10
时间: 2024-05-06 17:16:17 浏览: 18
这个问题可能是因为在 Windows 10 中,GetWindowLongPtrW 函数已被标记为弃用。您可以使用 GetWindowLongPtrA 或 GetWindowLongW 函数来代替。
您可以尝试以下代码,它将使用 GetWindowLongW 函数:
```
import ctypes
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
# 定义常量
GWL_EXSTYLE = -20
WS_EX_LAYERED = 0x00080000
# 获取窗口句柄
hwnd = user32.GetDesktopWindow()
# 获取窗口扩展样式
style = user32.GetWindowLongW(hwnd, GWL_EXSTYLE)
# 检查窗口是否启用了 WS_EX_LAYERED 扩展样式
if style & WS_EX_LAYERED:
print("Enabled")
else:
print("Not enabled")
```
如果您需要使用 GetWindowLongPtrW 函数,您可以使用 ctypes.wintypes 模块中的 LONG_PTR 数据类型来指定函数返回值的类型。例如:
```
import ctypes
from ctypes import wintypes
user32 = ctypes.windll.user32
gdi32 = ctypes.windll.gdi32
# 定义常量
GWL_EXSTYLE = -20
WS_EX_LAYERED = 0x00080000
# 获取窗口句柄
hwnd = user32.GetDesktopWindow()
# 获取窗口扩展样式
style = user32.GetWindowLongPtrW(hwnd, GWL_EXSTYLE)
# 检查窗口是否启用了 WS_EX_LAYERED 扩展样式
if style & WS_EX_LAYERED:
print("Enabled")
else:
print("Not enabled")
```
我希望这可以帮助您解决问题。