python - ctypes: passing and reading an enum pointer -


this page says:

enumeration types not implemented. can yourself, using c_int base class.

if easy, why isn't implemented yet? how get current color temperature of monitor, instance?

bool getmonitorcolortemperature(   _in_   handle hmonitor,   _out_  lpmc_color_temperature pctcurrentcolortemperature );  parameters  hmonitor [in]      handle physical monitor. monitor handle, call getphysicalmonitorsfromhmonitor or getphysicalmonitorsfromidirect3ddevice9. pctcurrentcolortemperature [out]      receives monitor's current color temperature, specified member of mc_color_temperature enumeration.  return value  if function succeeds, return value true. if function fails, return value false. extended error information, call getlasterror. 

this closest able get:

from ctypes import *  import win32api  # http://sourceforge.net/projects/pywin32/files/pywin32/  idx, (hmon, hdc, (left, top, right, bottom)) in enumerate(win32api.enumdisplaymonitors(none, none)):     print(hmon.handle)  # or int(hmon)  class myenum(c_int):     mc_color_temperature_unknown = 0     mc_color_temperature_4000k = 1     mc_color_temperature_5000k = 2     mc_color_temperature_6500k = 3     mc_color_temperature_7500k = 4     mc_color_temperature_8200k = 5     mc_color_temperature_9300k = 6     mc_color_temperature_10000k = 7     mc_color_temperature_11500k = 8  o = myenum() print(o) po = pointer(o) t = windll.dxva2.getmonitorcolortemperature(hmon.handle, po)  #byref(o)) #print(dir(o)) print(o) print(po.contents) print(t) print(windll.kernel32.getlasterror())  # error_graphics_invalid_physical_monitor_handle = -1071241844 # variable c_long '-0x03fd9da74' 

...returns this:

65537 65539 <myenum object @ 0x006f6da0> <myenum object @ 0x006f6da0> <myenum object @ 0x0234fad0> 0 -1071241844 

it's same either monitor handle. doing wrong?

using this answer, somehow found out works using none physical monitor handle:

from ctypes import * ctypes.wintypes import bool, hmonitor, hdc, rect, lparam, dword, byte, wchar, handle  import win32api  # http://sourceforge.net/projects/pywin32/files/pywin32/  _monitorenumproc = winfunctype(bool, hmonitor, hdc, pointer(rect), lparam)  class _physical_monitor(structure):     _fields_ = [('handle', handle),                 ('description', wchar * 128)]   def _iter_physical_monitors(close_handles=true):     """iterates physical monitors.      handles closed automatically whenever iterator advanced.     means iterator should exhausted!      if want keep handles e.g. because need store of them ,     use them later, set `close_handles` false , close them manually."""      def callback(hmonitor, hdc, lprect, lparam):         monitors.append(hmonitor)         return true      monitors = []     if not windll.user32.enumdisplaymonitors(none, none, _monitorenumproc(callback), none):         raise winerror('enumdisplaymonitors failed')      monitor in monitors:         # physical monitor count         count = dword()         if not windll.dxva2.getnumberofphysicalmonitorsfromhmonitor(monitor, byref(count)):             raise winerror()         # physical monitor handles         physical_array = (_physical_monitor * count.value)()         if not windll.dxva2.getphysicalmonitorsfromhmonitor(monitor, count.value, physical_array):             raise winerror()         physical in physical_array:             yield physical.handle             if close_handles:                 if not windll.dxva2.destroyphysicalmonitor(physical.handle):                     raise winerror()  mons = [m m in _iter_physical_monitors(false)]  #for idx, (hmon, hdc, (left, top, right, bottom)) in enumerate(win32api.enumdisplaymonitors(none, none)): #   print(hmon.handle)  # or int(hmon)  temps = (     'unknown',     '4000k',     '5000k',     '6500k',     '7500k',     '8200k',     '9300k',     '10000k',     '11500k' ) class myenum(c_int):     mc_color_temperature_unknown = 0     mc_color_temperature_4000k = 1     mc_color_temperature_5000k = 2     mc_color_temperature_6500k = 3     mc_color_temperature_7500k = 4     mc_color_temperature_8200k = 5     mc_color_temperature_9300k = 6     mc_color_temperature_10000k = 7     mc_color_temperature_11500k = 8  o = myenum() print(o) po = pointer(o)  pm = mons[0] print("physical %r" % pm) t = windll.dxva2.getmonitorcolortemperature(pm, po)  #byref(o)) if t:     #print(o)     #print(dir(po.contents))     print(temps[po.contents.value])  else:     print("err: %s" % windll.kernel32.getlasterror())  # error_graphics_invalid_physical_monitor_handle = -1071241844 # variable c_long '-0x03fd9da74' 

result:

<myenum object @ 0x005d6120> physical none 6500k 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -