windll.user32.GetWindowLongPtr(hwnd, self.GWL_EXSTYLE) 这段代码在我的系统上不起作用。我在使用win10
时间: 2024-05-09 18:15:05 浏览: 12
在 Windows 10 上,GetWindowLongPtr 函数被建议替换为 GetWindowLongPtrA 或 GetWindowLongPtrW 函数,并且需要在代码中使用条件编译指令。
请尝试使用以下代码:
```python
import sys
import ctypes
if sys.platform.startswith('win32'):
GWL_EXSTYLE = -20
if sys.maxsize > 2**32:
user32 = ctypes.WinDLL('user32', use_last_error=True)
GetWindowLongPtr = user32.GetWindowLongPtrW
else:
user32 = ctypes.windll.user32
GetWindowLongPtr = user32.GetWindowLongPtrA
GetWindowLongPtr.restype = ctypes.c_long
GetWindowLongPtr.argtypes = (ctypes.c_void_p, ctypes.c_int)
hwnd = ...
exstyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE)
```
这里我们先根据系统位数选择使用 GetWindowLongPtrA 或 GetWindowLongPtrW 函数,然后设置返回值类型和参数类型并调用函数即可。注意 GWL_EXSTYLE 常量也需要根据系统进行相应的修改。