home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2541 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  16.7 KB  |  536 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32gui
  5. import win32con
  6. import struct
  7. import array
  8. import commctrl
  9. import pywintypes
  10.  
  11. def UnpackWMNOTIFY(lparam):
  12.     format = 'iii'
  13.     buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
  14.     (hwndFrom, idFrom, code) = struct.unpack(format, buf)
  15.     return (hwndFrom, idFrom, code)
  16.  
  17. menuitem_fmt = '5i5PiP'
  18.  
  19. def PackMENUITEMINFO(fType = None, fState = None, wID = None, hSubMenu = None, hbmpChecked = None, hbmpUnchecked = None, dwItemData = None, text = None, hbmpItem = None, dwTypeData = None):
  20.     extras = []
  21.     if dwTypeData is not None:
  22.         import warnings
  23.         warnings.warn('PackMENUITEMINFO: please use dwItemData instead of dwTypeData')
  24.     
  25.     if dwItemData is None:
  26.         if not dwTypeData:
  27.             pass
  28.         dwItemData = 0
  29.     
  30.     fMask = 0
  31.     if fType is None:
  32.         fType = 0
  33.     else:
  34.         fMask |= win32con.MIIM_FTYPE
  35.     if fState is None:
  36.         fState = 0
  37.     else:
  38.         fMask |= win32con.MIIM_STATE
  39.     if wID is None:
  40.         wID = 0
  41.     else:
  42.         fMask |= win32con.MIIM_ID
  43.     if hSubMenu is None:
  44.         hSubMenu = 0
  45.     else:
  46.         fMask |= win32con.MIIM_SUBMENU
  47.     if hbmpChecked is None:
  48.         hbmpChecked = hbmpUnchecked = 0
  49.     else:
  50.         fMask |= win32con.MIIM_CHECKMARKS
  51.     if dwItemData is None:
  52.         dwItemData = 0
  53.     else:
  54.         fMask |= win32con.MIIM_DATA
  55.     if hbmpItem is None:
  56.         hbmpItem = 0
  57.     else:
  58.         fMask |= win32con.MIIM_BITMAP
  59.     if text is not None:
  60.         fMask |= win32con.MIIM_STRING
  61.         if isinstance(text, unicode):
  62.             text = text.encode('mbcs')
  63.         
  64.         str_buf = array.array('c', text + '\x00')
  65.         cch = len(str_buf)
  66.         lptext = str_buf.buffer_info()[0]
  67.         extras.append(str_buf)
  68.     else:
  69.         lptext = 0
  70.         cch = 0
  71.     item = struct.pack(menuitem_fmt, struct.calcsize(menuitem_fmt), fMask, fType, fState, wID, long(hSubMenu), long(hbmpChecked), long(hbmpUnchecked), dwItemData, lptext, cch, long(hbmpItem))
  72.     return (array.array('c', item), extras)
  73.  
  74.  
  75. def UnpackMENUITEMINFO(s):
  76.     (cb, fMask, fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData, lptext, cch, hbmpItem) = struct.unpack(menuitem_fmt, s)
  77.     if fMask & win32con.MIIM_FTYPE == 0:
  78.         fType = None
  79.     
  80.     if fMask & win32con.MIIM_STATE == 0:
  81.         fState = None
  82.     
  83.     if fMask & win32con.MIIM_ID == 0:
  84.         wID = None
  85.     
  86.     if fMask & win32con.MIIM_SUBMENU == 0:
  87.         hSubMenu = None
  88.     
  89.     if fMask & win32con.MIIM_CHECKMARKS == 0:
  90.         hbmpChecked = None
  91.         hbmpUnchecked = None
  92.     
  93.     if fMask & win32con.MIIM_DATA == 0:
  94.         dwItemData = None
  95.     
  96.     if fMask & win32con.MIIM_BITMAP == 0:
  97.         hbmpItem = None
  98.     
  99.     if fMask & win32con.MIIM_STRING:
  100.         text = win32gui.PyGetString(lptext, cch)
  101.     else:
  102.         text = None
  103.     return (fType, fState, wID, hSubMenu, hbmpChecked, hbmpUnchecked, dwItemData, text, hbmpItem)
  104.  
  105.  
  106. def EmptyMENUITEMINFO(mask = None, text_buf_size = 512):
  107.     extra = []
  108.     if mask is None:
  109.         mask = win32con.MIIM_BITMAP | win32con.MIIM_CHECKMARKS | win32con.MIIM_DATA | win32con.MIIM_FTYPE | win32con.MIIM_ID | win32con.MIIM_STATE | win32con.MIIM_STRING | win32con.MIIM_SUBMENU
  110.     
  111.     if mask & win32con.MIIM_STRING:
  112.         text_buffer = array.array('c', '\x00' * text_buf_size)
  113.         extra.append(text_buffer)
  114.         (text_addr, text_len) = text_buffer.buffer_info()
  115.     else:
  116.         text_addr = text_len = 0
  117.     buf = struct.pack(menuitem_fmt, struct.calcsize(menuitem_fmt), mask, 0, 0, 0, 0, 0, 0, 0, text_addr, text_len, 0)
  118.     return (array.array('c', buf), extra)
  119.  
  120. menuinfo_fmt = '7i'
  121.  
  122. def PackMENUINFO(dwStyle = None, cyMax = None, hbrBack = None, dwContextHelpID = None, dwMenuData = None, fMask = 0):
  123.     if dwStyle is None:
  124.         dwStyle = 0
  125.     else:
  126.         fMask |= win32con.MIM_STYLE
  127.     if cyMax is None:
  128.         cyMax = 0
  129.     else:
  130.         fMask |= win32con.MIM_MAXHEIGHT
  131.     if hbrBack is None:
  132.         hbrBack = 0
  133.     else:
  134.         fMask |= win32con.MIM_BACKGROUND
  135.     if dwContextHelpID is None:
  136.         dwContextHelpID = 0
  137.     else:
  138.         fMask |= win32con.MIM_HELPID
  139.     if dwMenuData is None:
  140.         dwMenuData = 0
  141.     else:
  142.         fMask |= win32con.MIM_MENUDATA
  143.     item = struct.pack(menuinfo_fmt, struct.calcsize(menuinfo_fmt), fMask, dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData)
  144.     return array.array('c', item)
  145.  
  146.  
  147. def UnpackMENUINFO(s):
  148.     (cb, fMask, dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData) = struct.unpack(menuinfo_fmt, s)
  149.     if fMask & win32con.MIM_STYLE == 0:
  150.         dwStyle = None
  151.     
  152.     if fMask & win32con.MIM_MAXHEIGHT == 0:
  153.         cyMax = None
  154.     
  155.     if fMask & win32con.MIM_BACKGROUND == 0:
  156.         hbrBack = None
  157.     
  158.     if fMask & win32con.MIM_HELPID == 0:
  159.         dwContextHelpID = None
  160.     
  161.     if fMask & win32con.MIM_MENUDATA == 0:
  162.         dwMenuData = None
  163.     
  164.     return (dwStyle, cyMax, hbrBack, dwContextHelpID, dwMenuData)
  165.  
  166.  
  167. def EmptyMENUINFO(mask = None):
  168.     if mask is None:
  169.         mask = win32con.MIM_STYLE | win32con.MIM_MAXHEIGHT | win32con.MIM_BACKGROUND | win32con.MIM_HELPID | win32con.MIM_MENUDATA
  170.     
  171.     buf = struct.pack(menuinfo_fmt, struct.calcsize(menuinfo_fmt), mask, 0, 0, 0, 0, 0)
  172.     return array.array('c', buf)
  173.  
  174.  
  175. def _GetMaskAndVal(val, default, mask, flag):
  176.     if val is None:
  177.         return (mask, default)
  178.     if flag is not None:
  179.         mask |= flag
  180.     
  181.     return (mask, val)
  182.  
  183.  
  184. def PackTVINSERTSTRUCT(parent, insertAfter, tvitem):
  185.     (tvitem_buf, extra) = PackTVITEM(*tvitem)
  186.     tvitem_buf = tvitem_buf.tostring()
  187.     format = 'ii%ds' % len(tvitem_buf)
  188.     return (struct.pack(format, parent, insertAfter, tvitem_buf), extra)
  189.  
  190.  
  191. def PackTVITEM(hitem, state, stateMask, text, image, selimage, citems, param):
  192.     extra = []
  193.     mask = 0
  194.     (mask, hitem) = _GetMaskAndVal(hitem, 0, mask, commctrl.TVIF_HANDLE)
  195.     (mask, state) = _GetMaskAndVal(state, 0, mask, commctrl.TVIF_STATE)
  196.     if not mask & commctrl.TVIF_STATE:
  197.         stateMask = 0
  198.     
  199.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.TVIF_TEXT)
  200.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.TVIF_IMAGE)
  201.     (mask, selimage) = _GetMaskAndVal(selimage, 0, mask, commctrl.TVIF_SELECTEDIMAGE)
  202.     (mask, citems) = _GetMaskAndVal(citems, 0, mask, commctrl.TVIF_CHILDREN)
  203.     (mask, param) = _GetMaskAndVal(param, 0, mask, commctrl.TVIF_PARAM)
  204.     if text is None:
  205.         text_addr = text_len = 0
  206.     elif isinstance(text, unicode):
  207.         text = text.encode('mbcs')
  208.     
  209.     text_buffer = array.array('c', text + '\x00')
  210.     extra.append(text_buffer)
  211.     (text_addr, text_len) = text_buffer.buffer_info()
  212.     format = 'iiiiiiiiii'
  213.     buf = struct.pack(format, mask, hitem, state, stateMask, text_addr, text_len, image, selimage, citems, param)
  214.     return (array.array('c', buf), extra)
  215.  
  216.  
  217. def EmptyTVITEM(hitem, mask = None, text_buf_size = 512):
  218.     extra = []
  219.     if mask is None:
  220.         mask = commctrl.TVIF_HANDLE | commctrl.TVIF_STATE | commctrl.TVIF_TEXT | commctrl.TVIF_IMAGE | commctrl.TVIF_SELECTEDIMAGE | commctrl.TVIF_CHILDREN | commctrl.TVIF_PARAM
  221.     
  222.     if mask & commctrl.TVIF_TEXT:
  223.         text_buffer = array.array('c', '\x00' * text_buf_size)
  224.         extra.append(text_buffer)
  225.         (text_addr, text_len) = text_buffer.buffer_info()
  226.     else:
  227.         text_addr = text_len = 0
  228.     format = 'iiiiiiiiii'
  229.     buf = struct.pack(format, mask, hitem, 0, 0, text_addr, text_len, 0, 0, 0, 0)
  230.     return (array.array('c', buf), extra)
  231.  
  232.  
  233. def UnpackTVITEM(buffer):
  234.     (item_mask, item_hItem, item_state, item_stateMask, item_textptr, item_cchText, item_image, item_selimage, item_cChildren, item_param) = struct.unpack('10i', buffer)
  235.     if not item_mask & commctrl.TVIF_TEXT:
  236.         item_textptr = None
  237.         item_cchText = None
  238.     
  239.     if not item_mask & commctrl.TVIF_CHILDREN:
  240.         item_cChildren = None
  241.     
  242.     if not item_mask & commctrl.TVIF_IMAGE:
  243.         item_image = None
  244.     
  245.     if not item_mask & commctrl.TVIF_PARAM:
  246.         item_param = None
  247.     
  248.     if not item_mask & commctrl.TVIF_SELECTEDIMAGE:
  249.         item_selimage = None
  250.     
  251.     if not item_mask & commctrl.TVIF_STATE:
  252.         item_state = None
  253.         item_stateMask = None
  254.     
  255.     if item_textptr:
  256.         text = win32gui.PyGetString(item_textptr)
  257.     else:
  258.         text = None
  259.     return (item_hItem, item_state, item_stateMask, text, item_image, item_selimage, item_cChildren, item_param)
  260.  
  261.  
  262. def UnpackTVNOTIFY(lparam):
  263.     format = 'iiii40s40s'
  264.     buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
  265.     (hwndFrom, id, code, action, buf_old, buf_new) = struct.unpack(format, buf)
  266.     item_old = UnpackTVITEM(buf_old)
  267.     item_new = UnpackTVITEM(buf_new)
  268.     return (hwndFrom, id, code, action, item_old, item_new)
  269.  
  270.  
  271. def UnpackTVDISPINFO(lparam):
  272.     format = 'iii40s'
  273.     buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
  274.     (hwndFrom, id, code, buf_item) = struct.unpack(format, buf)
  275.     item = UnpackTVITEM(buf_item)
  276.     return (hwndFrom, id, code, item)
  277.  
  278.  
  279. def PackLVITEM(item = None, subItem = None, state = None, stateMask = None, text = None, image = None, param = None, indent = None):
  280.     extra = []
  281.     mask = 0
  282.     if item is None:
  283.         item = 0
  284.     
  285.     if subItem is None:
  286.         subItem = 0
  287.     
  288.     if state is None:
  289.         state = 0
  290.         stateMask = 0
  291.     else:
  292.         mask |= commctrl.LVIF_STATE
  293.         if stateMask is None:
  294.             stateMask = state
  295.         
  296.     if image is None:
  297.         image = 0
  298.     else:
  299.         mask |= commctrl.LVIF_IMAGE
  300.     if param is None:
  301.         param = 0
  302.     else:
  303.         mask |= commctrl.LVIF_PARAM
  304.     if indent is None:
  305.         indent = 0
  306.     else:
  307.         mask |= commctrl.LVIF_INDENT
  308.     if text is None:
  309.         text_addr = text_len = 0
  310.     else:
  311.         mask |= commctrl.LVIF_TEXT
  312.         if isinstance(text, unicode):
  313.             text = text.encode('mbcs')
  314.         
  315.         text_buffer = array.array('c', text + '\x00')
  316.         extra.append(text_buffer)
  317.         (text_addr, text_len) = text_buffer.buffer_info()
  318.     format = 'iiiiiiiiii'
  319.     buf = struct.pack(format, mask, item, subItem, state, stateMask, text_addr, text_len, image, param, indent)
  320.     return (array.array('c', buf), extra)
  321.  
  322.  
  323. def UnpackLVITEM(buffer):
  324.     (item_mask, item_item, item_subItem, item_state, item_stateMask, item_textptr, item_cchText, item_image, item_param, item_indent) = struct.unpack('10i', buffer)
  325.     if not item_mask & commctrl.LVIF_TEXT:
  326.         item_textptr = None
  327.         item_cchText = None
  328.     
  329.     if not item_mask & commctrl.LVIF_IMAGE:
  330.         item_image = None
  331.     
  332.     if not item_mask & commctrl.LVIF_PARAM:
  333.         item_param = None
  334.     
  335.     if not item_mask & commctrl.LVIF_INDENT:
  336.         item_indent = None
  337.     
  338.     if not item_mask & commctrl.LVIF_STATE:
  339.         item_state = None
  340.         item_stateMask = None
  341.     
  342.     if item_textptr:
  343.         text = win32gui.PyGetString(item_textptr)
  344.     else:
  345.         text = None
  346.     return (item_item, item_subItem, item_state, item_stateMask, text, item_image, item_param, item_indent)
  347.  
  348.  
  349. def UnpackLVDISPINFO(lparam):
  350.     format = 'iii40s'
  351.     buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
  352.     (hwndFrom, id, code, buf_item) = struct.unpack(format, buf)
  353.     item = UnpackLVITEM(buf_item)
  354.     return (hwndFrom, id, code, item)
  355.  
  356.  
  357. def UnpackLVNOTIFY(lparam):
  358.     format = '3i8i'
  359.     buf = win32gui.PyMakeBuffer(struct.calcsize(format), lparam)
  360.     (hwndFrom, id, code, item, subitem, newstate, oldstate, changed, pt_x, pt_y, lparam) = struct.unpack(format, buf)
  361.     return (hwndFrom, id, code, item, subitem, newstate, oldstate, changed, (pt_x, pt_y), lparam)
  362.  
  363.  
  364. def EmptyLVITEM(item, subitem, mask = None, text_buf_size = 512):
  365.     extra = []
  366.     if mask is None:
  367.         mask = commctrl.LVIF_IMAGE | commctrl.LVIF_INDENT | commctrl.LVIF_TEXT | commctrl.LVIF_PARAM | commctrl.LVIF_STATE
  368.     
  369.     if mask & commctrl.LVIF_TEXT:
  370.         text_buffer = array.array('c', '\x00' * text_buf_size)
  371.         extra.append(text_buffer)
  372.         (text_addr, text_len) = text_buffer.buffer_info()
  373.     else:
  374.         text_addr = text_len = 0
  375.     format = 'iiiiiiiiii'
  376.     buf = struct.pack(format, mask, item, subitem, 0, 0, text_addr, text_len, 0, 0, 0)
  377.     return (array.array('c', buf), extra)
  378.  
  379.  
  380. def PackLVCOLUMN(fmt = None, cx = None, text = None, subItem = None, image = None, order = None):
  381.     extra = []
  382.     mask = 0
  383.     (mask, fmt) = _GetMaskAndVal(fmt, 0, mask, commctrl.LVCF_FMT)
  384.     (mask, cx) = _GetMaskAndVal(cx, 0, mask, commctrl.LVCF_WIDTH)
  385.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.LVCF_TEXT)
  386.     (mask, subItem) = _GetMaskAndVal(subItem, 0, mask, commctrl.LVCF_SUBITEM)
  387.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.LVCF_IMAGE)
  388.     (mask, order) = _GetMaskAndVal(order, 0, mask, commctrl.LVCF_ORDER)
  389.     if text is None:
  390.         text_addr = text_len = 0
  391.     elif isinstance(text, unicode):
  392.         text = text.encode('mbcs')
  393.     
  394.     text_buffer = array.array('c', text + '\x00')
  395.     extra.append(text_buffer)
  396.     (text_addr, text_len) = text_buffer.buffer_info()
  397.     format = 'iiiiiiii'
  398.     buf = struct.pack(format, mask, fmt, cx, text_addr, text_len, subItem, image, order)
  399.     return (array.array('c', buf), extra)
  400.  
  401.  
  402. def UnpackLVCOLUMN(lparam):
  403.     format = 'iiiiiiii'
  404.     (mask, fmt, cx, text_addr, text_size, subItem, image, order) = struct.unpack(format, lparam)
  405.     if not mask & commctrl.LVCF_FMT:
  406.         fmt = None
  407.     
  408.     if not mask & commctrl.LVCF_WIDTH:
  409.         cx = None
  410.     
  411.     if not mask & commctrl.LVCF_TEXT:
  412.         text_addr = None
  413.         text_size = None
  414.     
  415.     if not mask & commctrl.LVCF_SUBITEM:
  416.         subItem = None
  417.     
  418.     if not mask & commctrl.LVCF_IMAGE:
  419.         image = None
  420.     
  421.     if not mask & commctrl.LVCF_ORDER:
  422.         order = None
  423.     
  424.     if text_addr:
  425.         text = win32gui.PyGetString(text_addr)
  426.     else:
  427.         text = None
  428.     return (fmt, cx, text, subItem, image, order)
  429.  
  430.  
  431. def EmptyLVCOLUMN(mask = None, text_buf_size = 512):
  432.     extra = []
  433.     if mask is None:
  434.         mask = commctrl.LVCF_FMT | commctrl.LVCF_WIDTH | commctrl.LVCF_TEXT | commctrl.LVCF_SUBITEM | commctrl.LVCF_IMAGE | commctrl.LVCF_ORDER
  435.     
  436.     if mask & commctrl.LVCF_TEXT:
  437.         text_buffer = array.array('c', '\x00' * text_buf_size)
  438.         extra.append(text_buffer)
  439.         (text_addr, text_len) = text_buffer.buffer_info()
  440.     else:
  441.         text_addr = text_len = 0
  442.     format = 'iiiiiiii'
  443.     buf = struct.pack(format, mask, 0, 0, text_addr, text_len, 0, 0, 0)
  444.     return (array.array('c', buf), extra)
  445.  
  446.  
  447. def PackLVHITTEST(pt):
  448.     format = 'iiiii'
  449.     buf = struct.pack(format, pt[0], pt[1], 0, 0, 0)
  450.     return (array.array('c', buf), None)
  451.  
  452.  
  453. def UnpackLVHITTEST(buf):
  454.     format = 'iiiii'
  455.     (x, y, flags, item, subitem) = struct.unpack(format, buf)
  456.     return ((x, y), flags, item, subitem)
  457.  
  458.  
  459. def PackHDITEM(cxy = None, text = None, hbm = None, fmt = None, param = None, image = None, order = None):
  460.     extra = []
  461.     mask = 0
  462.     (mask, cxy) = _GetMaskAndVal(cxy, 0, mask, commctrl.HDI_HEIGHT)
  463.     (mask, text) = _GetMaskAndVal(text, None, mask, commctrl.LVCF_TEXT)
  464.     (mask, hbm) = _GetMaskAndVal(hbm, 0, mask, commctrl.HDI_BITMAP)
  465.     (mask, fmt) = _GetMaskAndVal(fmt, 0, mask, commctrl.HDI_FORMAT)
  466.     (mask, param) = _GetMaskAndVal(param, 0, mask, commctrl.HDI_LPARAM)
  467.     (mask, image) = _GetMaskAndVal(image, 0, mask, commctrl.HDI_IMAGE)
  468.     (mask, order) = _GetMaskAndVal(order, 0, mask, commctrl.HDI_ORDER)
  469.     if text is None:
  470.         text_addr = text_len = 0
  471.     elif isinstance(text, unicode):
  472.         text = text.encode('mbcs')
  473.     
  474.     text_buffer = array.array('c', text + '\x00')
  475.     extra.append(text_buffer)
  476.     (text_addr, text_len) = text_buffer.buffer_info()
  477.     format = 'iiiiiiiiiii'
  478.     buf = struct.pack(format, mask, cxy, text_addr, hbm, text_len, fmt, param, image, order, 0, 0)
  479.     return (array.array('c', buf), extra)
  480.  
  481.  
  482. def PackDEV_BROADCAST(devicetype, rest_fmt, rest_data, extra_data = ''):
  483.     extra_data += '\x00' * (4 - len(extra_data) % 4)
  484.     format = 'iii' + rest_fmt
  485.     full_size = struct.calcsize(format) + len(extra_data)
  486.     data = (full_size, devicetype, 0) + rest_data
  487.     return struct.pack(format, *data) + extra_data
  488.  
  489.  
  490. def PackDEV_BROADCAST_HANDLE(handle, hdevnotify = 0, guid = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', name_offset = 0, data = '\x00'):
  491.     return PackDEV_BROADCAST(win32con.DBT_DEVTYP_HANDLE, 'PP16sl', (long(handle), long(hdevnotify), str(buffer(guid)), name_offset), data)
  492.  
  493.  
  494. def PackDEV_BROADCAST_DEVICEINTERFACE(classguid, name = ''):
  495.     rest_fmt = '16s%ds' % len(name)
  496.     rest_data = (str(buffer(pywintypes.IID(classguid))), name)
  497.     return PackDEV_BROADCAST(win32con.DBT_DEVTYP_DEVICEINTERFACE, rest_fmt, rest_data)
  498.  
  499.  
  500. class DEV_BROADCAST_INFO:
  501.     
  502.     def __init__(self, devicetype, **kw):
  503.         self.devicetype = devicetype
  504.         self.__dict__.update(kw)
  505.  
  506.     
  507.     def __str__(self):
  508.         return 'DEV_BROADCAST_INFO:' + str(self.__dict__)
  509.  
  510.  
  511.  
  512. def UnpackDEV_BROADCAST(lparam):
  513.     if lparam == 0:
  514.         return None
  515.     hdr_size = struct.calcsize('iii')
  516.     hdr_buf = win32gui.PyMakeBuffer(hdr_size, lparam)
  517.     (size, devtype, reserved) = struct.unpack('iii', hdr_buf)
  518.     rest = win32gui.PyMakeBuffer(size - hdr_size, lparam + hdr_size)
  519.     if devtype == win32con.DBT_DEVTYP_HANDLE:
  520.         fmt = 'PP16sl'
  521.         (x['handle'], x['hdevnotify'], guid_bytes, x['nameoffset']) = struct.unpack(fmt, rest[:struct.calcsize(fmt)])
  522.         x['eventguid'] = pywintypes.IID(guid_bytes, True)
  523.     elif devtype == win32con.DBT_DEVTYP_DEVICEINTERFACE:
  524.         x['classguid'] = pywintypes.IID(rest[:16], 1)
  525.         name = rest[16:]
  526.         if '\x00' in name:
  527.             name = name.split('\x00', 1)[0]
  528.         
  529.         x['name'] = name
  530.     elif devtype == win32con.DBT_DEVTYP_VOLUME:
  531.         (x['unitmask'], x['flags']) = struct.unpack('II', rest[:struct.calcsize('II')])
  532.     else:
  533.         raise NotImplementedError('unknown device type %d' % (devtype,))
  534.     return lparam == 0(devtype, **extra)
  535.  
  536.