def _getMonitorInfo(self):
        """ Returns info about the attached monitors, in device order

        [0] is always the primary monitor
        """
        monitors = []
        CCHDEVICENAME = 32
        def _MonitorEnumProcCallback(hMonitor, hdcMonitor, lprcMonitor, dwData):
            class MONITORINFOEX(ctypes.Structure):
                _fields_ = [("cbSize", ctypes.wintypes.DWORD),
                            ("rcMonitor", ctypes.wintypes.RECT),
                            ("rcWork", ctypes.wintypes.RECT),
                            ("dwFlags", ctypes.wintypes.DWORD),
                            ("szDevice", ctypes.wintypes.WCHAR*CCHDEVICENAME)]
            lpmi = MONITORINFOEX()
            lpmi.cbSize = ctypes.sizeof(MONITORINFOEX)
            self._user32.GetMonitorInfoW(hMonitor, ctypes.byref(lpmi))
            #hdc = self._gdi32.CreateDCA(ctypes.c_char_p(lpmi.szDevice), 0, 0, 0)
            monitors.append({
                "hmon": hMonitor,
                #"hdc":  hdc,
                "rect": (lprcMonitor.contents.left,
                         lprcMonitor.contents.top,
                         lprcMonitor.contents.right,
                         lprcMonitor.contents.bottom),
                "name": lpmi.szDevice
                })
            return True
        MonitorEnumProc = ctypes.WINFUNCTYPE(
            ctypes.c_bool,
            ctypes.c_ulong,
            ctypes.c_ulong,
            ctypes.POINTER(ctypes.wintypes.RECT),
            ctypes.c_int)
        callback = MonitorEnumProc(_MonitorEnumProcCallback)
        if self._user32.EnumDisplayMonitors(0, 0, callback, 0) == 0:
            raise WindowsError("Unable to enumerate monitors")
        # Clever magic to make the screen with origin of (0,0) [the primary monitor]
        # the first in the list
        # Sort by device ID - 0 is primary, 1 is next, etc.
        monitors.sort(key=lambda x: (not (x["rect"][0] == 0 and x["rect"][1] == 0), x["name"]))

        return monitors
def _getMonitorInfo ( self ) : monitors = [ ] CCHDEVICENAME = 32 def _MonitorEnumProcCallback ( hMonitor , hdcMonitor , lprcMonitor , dwData ) : class MONITORINFOEX ( ctypes . Structure ) : _fields_ = [ ( "cbSize" , ctypes . wintypes . DWORD ) , ( "rcMonitor" , ctypes . wintypes . RECT ) , ( "rcWork" , ctypes . wintypes . RECT ) , ( "dwFlags" , ctypes . wintypes . DWORD ) , ( "szDevice" , ctypes . wintypes . WCHAR * CCHDEVICENAME ) ] lpmi = MONITORINFOEX ( ) lpmi . cbSize = ctypes . sizeof ( MONITORINFOEX ) self . _user32 . GetMonitorInfoW ( hMonitor , ctypes . byref ( lpmi ) ) monitors . append ( { "hmon" : hMonitor , "rect" : ( lprcMonitor . contents . left , lprcMonitor . contents . top , lprcMonitor . contents . right , lprcMonitor . contents . bottom ) , "name" : lpmi . szDevice } ) return True MonitorEnumProc = ctypes . WINFUNCTYPE ( ctypes . c_bool , ctypes . c_ulong , ctypes . c_ulong , ctypes . POINTER ( ctypes . wintypes . RECT ) , ctypes . c_int ) callback = MonitorEnumProc ( _MonitorEnumProcCallback ) if self . _user32 . EnumDisplayMonitors ( 0 , 0 , callback , 0 ) == 0 : raise WindowsError ( "Unable to enumerate monitors" ) monitors . sort ( key = lambda x : ( not ( x [ "rect" ] [ 0 ] == 0 and x [ "rect" ] [ 1 ] == 0 ) , x [ "name" ] ) ) return monitors
Returns info about the attached monitors, in device order

        [0] is always the primary monitor