def OnMinMaxInfo (self, hwnd, msg, wparam, lparam): ur"""Prevent the dialog from resizing vertically by extracting the window's current size and using the minmaxinfo message to set the maximum & minimum window heights to be its current height. """ dlg_l, dlg_t, dlg_r, dlg_b = wrapped (win32gui.GetWindowRect, hwnd) # # If returning from minmization, do nothing # if wrapped (win32gui.GetClientRect, hwnd) == (0, 0, 0, 0): return 0 # # MINMAXINFO is a struct of 5 POINT items, each of which # is a pair of LONGs. We extract the structure into a list, # set the Y coord of MaxTrackSize and of MinTrackSize to be # the window's current height and write the data back into # the same place. # POINT_FORMAT = "LL" MINMAXINO_FORMAT = 5 * POINT_FORMAT data = win32gui.PyGetString (lparam, struct.calcsize (MINMAXINO_FORMAT)) minmaxinfo = list (struct.unpack (MINMAXINO_FORMAT, data)) minmaxinfo[9] = minmaxinfo[7] = dlg_b - dlg_t win32gui.PySetMemory (lparam, struct.pack (MINMAXINO_FORMAT, *minmaxinfo)) return 0
def OnProgressMessage(self, hwnd, msg, wparam, lparam): """Respond to a progress update from within the progress thread. LParam will be a pointer to a string containing a utf8-encoded string which is to be displayed in the dialog's progress static. """ message = marshal.loads(win32gui.PyGetString(lparam, wparam)) self._set_item(self._progress_id, message)
def OnProgressComplete(self, hwnd, msg, wparam, lparam): ur"""Respond to the a message signalling that all processing is now complete by re-enabling the ok button, disabling cancel, and setting focus to the ok so a return or space will close the dialog. """ message = marshal.loads(win32gui.PyGetString(lparam, wparam)) self._set_item(self._progress_id, message) self._enable(win32con.IDCANCEL, False) self._enable(win32con.IDOK, True) wrapped(win32gui.SetFocus, wrapped(win32gui.GetDlgItem, hwnd, win32con.IDOK))
def OnProgressComplete(self, hwnd, msg, wparam, lparam): """Respond to the a message signalling that all processing is now complete by re-enabling the ok button, disabling cancel, and setting focus to the ok so a return or space will close the dialog. """ try: message = marshal.loads(win32gui.PyGetString(lparam, wparam)) except ValueError: message = "- Complete -" self._set_item(self._progress_id, message) self._enable(win32con.IDCANCEL, False) self._enable(win32con.IDOK, True) PostMessage(self.hwnd, win32con.WM_QUIT, 0, 0)
def OnDrawItem(self, hwnd, msg, wparam, lparam): fmt = "5i2P4iP" data = struct.unpack( fmt, win32gui.PyGetString(lparam, struct.calcsize(fmt))) ctlType, ctlID, itemID, itemAction, itemState, hwndItem, \ hDC, left, top, right, bot, itemData = data rect = left, top, right, bot hicon, text = self.menu_item_map[itemData] if text is None: # This means the menu-item had HBMMENU_CALLBACK - so all we # draw is the icon. rect is the entire area we should use. win32gui.DrawIconEx(hDC, left, top, hicon, right - left, bot - top, 0, 0, win32con.DI_NORMAL) else: # If the user has selected the item, use the selected # text and background colors to display the item. selected = itemState & win32con.ODS_SELECTED if selected: crText = win32gui.SetTextColor( hDC, win32gui.GetSysColor(win32con.COLOR_HIGHLIGHTTEXT)) crBkgnd = win32gui.SetBkColor( hDC, win32gui.GetSysColor(win32con.COLOR_HIGHLIGHT)) each_pad = self.icon_x_pad // 2 x_icon = left + each_pad x_text = x_icon + self.menu_icon_width + each_pad # Draw text first, specifying a complete rect to fill - this sets # up the background (but overwrites anything else already there!) # Select the font, draw it, and restore the previous font. hfontOld = win32gui.SelectObject(hDC, self.font_menu) win32gui.ExtTextOut(hDC, x_text, top + 2, win32con.ETO_OPAQUE, rect, text) win32gui.SelectObject(hDC, hfontOld) # Icon image next. Icons are transparent - no need to handle # selection specially. win32gui.DrawIconEx(hDC, x_icon, top + 2, hicon, self.menu_icon_width, self.menu_icon_height, 0, 0, win32con.DI_NORMAL) # Return the text and background colors to their # normal state (not selected). if selected: win32gui.SetTextColor(hDC, crText) win32gui.SetBkColor(hDC, crBkgnd)
def pointer_as_string(pointer, length=0): """Convert a WinAPI LPSTR to a Python string""" return win32gui.PyGetString(pointer, length)