示例#1
0
 def nativeEvent(self, eventType, message):
     """ 处理windows消息 """
     msg = MSG.from_address(message.__int__())
     if msg.message == win32con.WM_NCHITTEST:
         # 解决多屏下会出现鼠标一直为拖动状态的问题
         xPos = (win32api.LOWORD(msg.lParam) -
                 self.frameGeometry().x()) % 65536
         yPos = win32api.HIWORD(msg.lParam) - self.frameGeometry().y()
         w, h = self.width(), self.height()
         lx = xPos < self.BORDER_WIDTH
         rx = xPos + 9 > w - self.BORDER_WIDTH
         ty = yPos < self.BORDER_WIDTH
         by = yPos > h - self.BORDER_WIDTH
         if lx and ty:
             return True, win32con.HTTOPLEFT
         elif rx and by:
             return True, win32con.HTBOTTOMRIGHT
         elif rx and ty:
             return True, win32con.HTTOPRIGHT
         elif lx and by:
             return True, win32con.HTBOTTOMLEFT
         elif ty:
             return True, win32con.HTTOP
         elif by:
             return True, win32con.HTBOTTOM
         elif lx:
             return True, win32con.HTLEFT
         elif rx:
             return True, win32con.HTRIGHT
     elif msg.message == win32con.WM_NCCALCSIZE:
         if self.isWindowMaximized(msg.hWnd):
             self.monitorNCCALCSIZE(msg)
         return True, 0
     elif msg.message == win32con.WM_GETMINMAXINFO:
         if self.isWindowMaximized(msg.hWnd):
             window_rect = win32gui.GetWindowRect(msg.hWnd)
             if not window_rect:
                 return False, 0
             # 获取显示器句柄
             monitor = win32api.MonitorFromRect(window_rect)
             if not monitor:
                 return False, 0
             # 获取显示器信息
             monitor_info = win32api.GetMonitorInfo(monitor)
             monitor_rect = monitor_info['Monitor']
             work_area = monitor_info['Work']
             # 将lParam转换为MINMAXINFO指针
             info = cast(msg.lParam, POINTER(MINMAXINFO)).contents
             # 调整窗口大小
             info.ptMaxSize.x = work_area[2] - work_area[0]
             info.ptMaxSize.y = work_area[3] - work_area[1]
             info.ptMaxTrackSize.x = info.ptMaxSize.x
             info.ptMaxTrackSize.y = info.ptMaxSize.y
             # 修改左上角坐标
             info.ptMaxPosition.x = abs(window_rect[0] - monitor_rect[0])
             info.ptMaxPosition.y = abs(window_rect[1] - monitor_rect[1])
             return True, 1
     return QWidget.nativeEvent(self, eventType, message)
示例#2
0
 def monitorNCCALCSIZE(self, msg: MSG):
     """ 调整窗口大小 """
     monitor = win32api.MonitorFromWindow(msg.hWnd)
     # 如果没有保存显示器信息就直接返回,否则接着调整窗口大小
     if monitor is None and not self.monitor_info:
         return
     elif monitor is not None:
         self.monitor_info = win32api.GetMonitorInfo(monitor)
     # 调整窗口大小
     params = cast(msg.lParam, POINTER(NCCALCSIZE_PARAMS)).contents
     params.rgrc[0].left = self.monitor_info['Work'][0]
     params.rgrc[0].top = self.monitor_info['Work'][1]
     params.rgrc[0].right = self.monitor_info['Work'][2]
     params.rgrc[0].bottom = self.monitor_info['Work'][3]
示例#3
0
    def __update(self):
        """Refresh monitor attributes."""

        # https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmonitorinfoa
        monitor_info = win32api.GetMonitorInfo(self.handle)

        # Get device name.
        self.__device = monitor_info['Device']

        # Get monitor coordinates.
        start_x, start_y, end_x, end_y = monitor_info['Monitor']

        # Calculate boundary object.
        self.__boundary = Boundary(start_x, start_y, end_x, end_y)

        pass
示例#4
0
    def __monitorNCCALCSIZE(self, msg: MSG):
        """ Adjust the size of window """
        monitor = win32api.MonitorFromWindow(msg.hWnd)

        # If the display information is not saved, return directly
        if monitor is None and not self.__monitorInfo:
            return
        elif monitor is not None:
            self.__monitorInfo = win32api.GetMonitorInfo(monitor)

        # adjust the size of window
        params = cast(msg.lParam, POINTER(NCCALCSIZE_PARAMS)).contents
        params.rgrc[0].left = self.__monitorInfo['Work'][0]
        params.rgrc[0].top = self.__monitorInfo['Work'][1]
        params.rgrc[0].right = self.__monitorInfo['Work'][2]
        params.rgrc[0].bottom = self.__monitorInfo['Work'][3]
示例#5
0
def get_display_info():
    return (win32api.GetMonitorInfo(hdsp)
            for hdsp, *_ in win32api.EnumDisplayMonitors())
示例#6
0
    if debug:
        print('Keyboard action detected, ' + str(event.Key) + ' was pressed.')
    if str(event.Key) == 'Lcontrol' or str(event.Key) == 'Rcontrol':
        hm.KeyDown = onWinCombo
        hm.KeyUp = cancelCombo
        return True
    else:
        return True


progParam = Tracker()

mons = win32api.EnumDisplayMonitors()
i = 0
while i < win32api.GetSystemMetrics(win32con.SM_CMONITORS):
    minfo = win32api.GetMonitorInfo(mons[i][0])
    progParam.l_monArray[i] = ([
        minfo['Monitor'][2] - minfo['Monitor'][0],
        minfo['Monitor'][3] - minfo['Monitor'][1]
    ], minfo['Monitor'][0], minfo['Monitor'][1], minfo['Monitor'][2],
                               minfo['Monitor'][3])
    i += 1
    if debug: print(minfo)
for key, rec in progParam.l_monArray.items():
    if vert:
        progParam.lSCREEN_HEIGHT += rec[0][1]
        progParam.lSCREEN_WIDTH = (
            rec[0][0]
        ) if progParam.lSCREEN_WIDTH < rec[0][0] else progParam.lSCREEN_WIDTH
        progParam.lYMAX = (
            rec[4]) if progParam.lYMAX < rec[4] else progParam.lYMAX
示例#7
0
    def nativeEvent(self, eventType, message):
        """ handle the Windows message """
        msg = MSG.from_address(message.__int__())
        if msg.message == win32con.WM_NCHITTEST:
            pos = QCursor.pos()
            xPos = pos.x() - self.x()
            yPos = pos.y() - self.y()
            w, h = self.width(), self.height()
            lx = xPos < self.BORDER_WIDTH
            rx = xPos > w - self.BORDER_WIDTH
            ty = yPos < self.BORDER_WIDTH
            by = yPos > h - self.BORDER_WIDTH
            if lx and ty:
                return True, win32con.HTTOPLEFT
            elif rx and by:
                return True, win32con.HTBOTTOMRIGHT
            elif rx and ty:
                return True, win32con.HTTOPRIGHT
            elif lx and by:
                return True, win32con.HTBOTTOMLEFT
            elif ty:
                return True, win32con.HTTOP
            elif by:
                return True, win32con.HTBOTTOM
            elif lx:
                return True, win32con.HTLEFT
            elif rx:
                return True, win32con.HTRIGHT
        elif msg.message == win32con.WM_NCCALCSIZE:
            if self._isWindowMaximized(msg.hWnd):
                self.__monitorNCCALCSIZE(msg)
            return True, 0
        elif msg.message == win32con.WM_GETMINMAXINFO:
            if self._isWindowMaximized(msg.hWnd):
                window_rect = win32gui.GetWindowRect(msg.hWnd)
                if not window_rect:
                    return False, 0

                # get the monitor handle
                monitor = win32api.MonitorFromRect(window_rect)
                if not monitor:
                    return False, 0

                # get the monitor information
                __monitorInfo = win32api.GetMonitorInfo(monitor)
                monitor_rect = __monitorInfo['Monitor']
                work_area = __monitorInfo['Work']

                # convert lParam to MINMAXINFO pointer
                info = cast(msg.lParam, POINTER(MINMAXINFO)).contents

                # adjust the size of window
                info.ptMaxSize.x = work_area[2] - work_area[0]
                info.ptMaxSize.y = work_area[3] - work_area[1]
                info.ptMaxTrackSize.x = info.ptMaxSize.x
                info.ptMaxTrackSize.y = info.ptMaxSize.y

                # modify the upper left coordinate
                info.ptMaxPosition.x = abs(window_rect[0] - monitor_rect[0])
                info.ptMaxPosition.y = abs(window_rect[1] - monitor_rect[1])
                return True, 1

        return QWidget.nativeEvent(self, eventType, message)