Skip to content

Commit 6dbe593

Browse files
committed
fixed LOWORD error #142 #172
1 parent fa48787 commit 6dbe593

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Demo/NativeEvent.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
try:
1919
from PyQt5.QtCore import Qt
20-
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
20+
from PyQt5.QtGui import QCursor
21+
from PyQt5.QtWidgets import QApplication, QPushButton, QWidget
2122
from PyQt5.QtWinExtras import QtWin
2223
except ImportError:
2324
from PySide2.QtCore import Qt
24-
from PySide2.QtWidgets import QWidget, QPushButton, QApplication
25+
from PySide2.QtGui import QCursor
26+
from PySide2.QtWidgets import QApplication, QPushButton, QWidget
2527
from PySide2.QtWinExtras import QtWin
2628

2729

@@ -43,16 +45,15 @@ def __init__(self, *args, **kwargs):
4345
# 主屏幕的可用大小(去掉任务栏)
4446
self._rect = QApplication.instance().desktop().availableGeometry(self)
4547
self.resize(800, 600)
46-
self.setWindowFlags(Qt.Window
47-
| Qt.FramelessWindowHint
48-
| Qt.WindowSystemMenuHint
49-
| Qt.WindowMinimizeButtonHint
50-
| Qt.WindowMaximizeButtonHint
51-
| Qt.WindowCloseButtonHint)
48+
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint |
49+
Qt.WindowSystemMenuHint |
50+
Qt.WindowMinimizeButtonHint |
51+
Qt.WindowMaximizeButtonHint |
52+
Qt.WindowCloseButtonHint)
5253
# 增加薄边框
5354
style = win32gui.GetWindowLong(int(self.winId()), win32con.GWL_STYLE)
54-
win32gui.SetWindowLong(
55-
int(self.winId()), win32con.GWL_STYLE, style | win32con.WS_THICKFRAME)
55+
win32gui.SetWindowLong(int(self.winId()), win32con.GWL_STYLE,
56+
style | win32con.WS_THICKFRAME)
5657

5758
if QtWin.isCompositionEnabled():
5859
# 加上 Aero 边框阴影
@@ -65,8 +66,9 @@ def nativeEvent(self, eventType, message):
6566
if eventType == "windows_generic_MSG":
6667
msg = ctypes.wintypes.MSG.from_address(message.__int__())
6768
# 获取鼠标移动经过时的坐标
68-
x = win32api.LOWORD(msg.lParam) - self.frameGeometry().x()
69-
y = win32api.HIWORD(msg.lParam) - self.frameGeometry().y()
69+
pos = QCursor.pos()
70+
x = pos.x() - self.frameGeometry().x()
71+
y = pos.y() - self.frameGeometry().y()
7072
# 判断鼠标位置是否有其它控件
7173
if self.childAt(x, y) != None:
7274
return retval, result
@@ -75,8 +77,8 @@ def nativeEvent(self, eventType, message):
7577
return True, 0
7678
if msg.message == win32con.WM_GETMINMAXINFO:
7779
# 当窗口位置改变或者大小改变时会触发该消息
78-
info = ctypes.cast(
79-
msg.lParam, ctypes.POINTER(MINMAXINFO)).contents
80+
info = ctypes.cast(msg.lParam,
81+
ctypes.POINTER(MINMAXINFO)).contents
8082
# 修改最大化的窗口大小为主屏幕的可用大小
8183
info.ptMaxSize.x = self._rect.width()
8284
info.ptMaxSize.y = self._rect.height()

0 commit comments

Comments
 (0)