예제 #1
0
    def open(self):
        if self.is_open:
            return

        desired_physical_number = self.monitor.info.monitor.device.number
        desired_device_name = self.monitor.info.adapter.device.name

        # We need to find the hMonitor for the desired monitor using EnumDisplayMonitors
        virtual_handle = HMONITOR()

        def callback(hMonitor: HMONITOR, hdcMonitor: HDC,
                     lprcMonitor: POINTER(RECT), dwData: LPARAM) -> bool:
            info = monitor_info.win32_get_monitor_info(hMonitor)

            if info.szDevice == desired_device_name:
                virtual_handle.value = hMonitor
                return False

            return True

        windll.user32.EnumDisplayMonitors(None, None,
                                          _MONITORENUMPROC(callback), None)

        if virtual_handle.value == 0:
            raise RuntimeError(
                f"Could not find a virtual handle for monitor {self.monitor}")

        # Get physical monitor count
        physical_count = DWORD()
        if not windll.dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR(
                virtual_handle, byref(physical_count)):
            raise WinError()
        assert (physical_count.value > desired_physical_number)

        # Get physical monitor handles
        physical_array = (_PHYSICAL_MONITOR * physical_count.value)()
        if not windll.dxva2.GetPhysicalMonitorsFromHMONITOR(
                virtual_handle, physical_count, physical_array):
            raise WinError()

        for i, physical in enumerate(physical_array):
            if i != desired_physical_number:
                self._close(physical.handle)

            self.handle = physical.handle

        self.is_open = True
 def callback(hmonitor, hdc, lprect, lparam):
     monitors.append(HMONITOR(hmonitor))
     return True
예제 #3
0
 def _callback(hmonitor, hdc, lprect, lparam):
     hmonitors.append(HMONITOR(hmonitor))
     del hmonitor, hdc, lprect, lparam
     return True  # continue enumeration
예제 #4
0
 def callback(hmonitor, hdc, pointer_rect, param):
     monitors.append(HMONITOR(hmonitor))
     return True