def ReadSnapshot(data): """extracts TBBUTTON and string array from the passed data.""" error = True data = create_string_buffer(data) if len(data) > (len(SNAP_COOKIE) + 12): # test for cookie if data[:3] == SNAP_COOKIE: n = len(SNAP_COOKIE) + 1 # version and sizeof ver = UINT.from_address(addressof(data) + n) n += 4 szeof = UINT.from_address(addressof(data) + n) n += 4 # get button array nButtons = UINT.from_address(addressof(data) + n) n += 4 szeofBt = nButtons.value * sizeof(TBBUTTON) if len(data) > szeofBt + n: arrBt = (TBBUTTON * nButtons.value)() memmove(addressof(arrBt), addressof(data) + n, szeofBt) n += szeofBt # get text array cchText = UINT.from_address(int(addressof(data) + n)) n += 4 if len(data) == n + cchText.value + 1: text = data[n:n + cchText.value] error = False if error: raise ValueError("invalid data") return arrBt, text
def ReadSnapshot(data): """extracts TBBUTTON and string array from the passed data.""" error = True data= create_string_buffer(data) if len(data) > (len(SNAP_COOKIE)+12): # test for cookie if data[:3]==SNAP_COOKIE: n= len(SNAP_COOKIE)+1 # version and sizeof ver= UINT.from_address(addressof(data)+n) n += 4 szeof= UINT.from_address(addressof(data)+n) n += 4 # get button array nButtons= UINT.from_address(addressof(data)+n) n += 4 szeofBt= nButtons.value*sizeof(TBBUTTON) if len(data) > szeofBt+n: arrBt= (TBBUTTON*nButtons.value)() memmove(addressof(arrBt), addressof(data)+n, szeofBt) n+= szeofBt # get text array cchText= UINT.from_address(int(addressof(data)+n)) n+= 4 if len(data)== n + cchText.value+1: text= data[n:n+cchText.value] error= False if error: raise ValueError("invalid data") return arrBt, text
def __init__(self, cookie, buttons): self.cbSize = sizeof(self) self.type = cookie self.nButtons = len(self.arrButtons) self.arrButtons = buttons self.textBuffer = [ None, ] * self.nButtons
def GetItemText(self, i): hd = HDITEM() hd.mask = hd.HDI_TEXT hd.pszText = addressof(self._client_buffer) hd.cchTextMax = sizeof(self._client_buffer) if self.SendMessage(self.Hwnd, self.Msg.HDM_GETITEM, i, byref(hd)): return self._client_buffer.value raise RuntimeError("could not retrive item text")
def GetItemText(self, i): tci = TCITEM() tci.mask = tci.TCIF_TEXT tci.pszText = addressof(self._client_buffer) tci.cchTextMax = sizeof(self._client_buffer) if not self.SendMessage(self.Hwnd, self.Msg.TCM_GETITEM, i, byref(tci)): raise RuntimeError("could not retrive text") return self._client_buffer.value
def _client_TruncText(self, text): """Truncates text to _client_buffer. Return value is address of buffer.""" n = len(text) szeof = sizeof(self._client_buffer) -1 if n > szeof: text = '%s...\x00' % text[:szeof-3] else: text = '%s\x00' % text self._client_buffer.raw = text return addressof(self._client_buffer)
def _client_TruncText(self, text): """Truncates text to _client_buffer. Return value is the address of the buffer.""" n = len(text) szeof = sizeof(self._client_buffer) -1 if n > szeof: text = '%s...\x00' % text[:szeof-3] else: text = '%s\x00' % text self._client_buffer.raw = text return addressof(self._client_buffer)
def GetBandTitle(self, ID): bi=REBARBANDINFO() bi.fMask = RBBIM_TEXT bi.lpText = addressof(self._client_buffer) bi.cch = sizeof(self._client_buffer) - 1 if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band title" return self._client_buffer.value
def SetImagelist(self, Imagelist): if Imagelist== None: handle= 0 else: handle= Imagelist.handle rbi=REBARINFO(sizeof(REBARINFO), RBIM_IMAGELIST, handle) if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBARINFO, 0, byref(rbi)): raise "could not set imagelist"
def GetBandTitle(self, ID): bi = REBARBANDINFO() bi.fMask = RBBIM_TEXT bi.lpText = addressof(self._client_buffer) bi.cch = sizeof(self._client_buffer) - 1 if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band title" return self._client_buffer.value
def _client_TruncText(self, text): """Truncates text to _client_buffer. Return value is the address of the buffer.""" text = text.replace('\t', " " * self._client_tabwidth) n = len(text) szeof = sizeof(self._client_buffer) - 1 if n > szeof: text = '%s...\x00' % text[:szeof - 3] else: text = '%s\x00' % text self._client_buffer.raw = text + '\x00' return addressof(self._client_buffer)
def _client_TruncText(self, text): """Truncates text to _client_buffer. Return value is the address of the buffer.""" text= text.replace('\t', " "*self._client_tabwidth) n = len(text) szeof = sizeof(self._client_buffer) -1 if n > szeof: text = '%s...\x00' % text[:szeof-3] else: text = '%s\x00' % text self._client_buffer.raw = text + '\x00' return addressof(self._client_buffer)
def SetImagelist(self, Imagelist): if Imagelist == None: handle = 0 else: handle = Imagelist.handle rbi = REBARINFO(sizeof(REBARINFO), RBIM_IMAGELIST, handle) if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBARINFO, 0, byref(rbi)): raise "could not set imagelist"
def GetEditControl(self, *flags): # get the editbox for the combo and subclass it p=create_string_buffer(5) flag= False for i in self.ChildWindows(): if user32.GetParent(i)==self.Hwnd: user32.GetClassNameA(i, p, sizeof(p)) if p.value.lower()=="edit": flag= True break if flag: txt= TextinFromHandle(i, 'subclass', *flags) fw.SetFlagMsgReflect(txt, False) return txt raise RuntimeError("could not retrieve edit control")
def GetIconIndex(self, path, *flags): flag = 16384 # SHGFI_SYSICONINDEX for i in flags: try: flag |= FILEINFO_FLAGS[i] except: raise ValueError("invalid flag: %s" % i) fileattributes = 0 if path[0]=='*': fileattributes = 128 # FILE_ATTRIBUTE_NORMAL flag |= 16 # SHGFI_USEFILEATTRIBUTES if path=='directory': fileattributes = 16 # FILE_ATTRIBUTE_DIRECTORY flag |= 16 # SHGFI_USEFILEATTRIBUTES fi = SHFILEINFO() if not shell32.SHGetFileInfoA(path, fileattributes, byref(fi), sizeof(SHFILEINFO), flag): raise RuntimeError("could not retrieve icon") return fi.iIcon
def GetIconIndex(self, path, *flags): flag = 16384 # SHGFI_SYSICONINDEX for i in flags: try: flag |= FILEINFO_FLAGS[i] except: raise ValueError("invalid flag: %s" % i) fileattributes = 0 if path[0] == '*': fileattributes = 128 # FILE_ATTRIBUTE_NORMAL flag |= 16 # SHGFI_USEFILEATTRIBUTES if path == 'directory': fileattributes = 16 # FILE_ATTRIBUTE_DIRECTORY flag |= 16 # SHGFI_USEFILEATTRIBUTES fi = SHFILEINFO() if not shell32.SHGetFileInfoA(path, fileattributes, byref(fi), sizeof(SHFILEINFO), flag): raise RuntimeError("could not retrieve icon") return fi.iIcon
def GetImagelist(self): rbi=REBARINFO(sizeof(REBARINFO), RBIM_IMAGELIST, 0) if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBARINFO, 0, byref(rbi)): raise "could not retrieve imagelist" if rbi.himl: return rbi.himl
def __init__(self): self.cbSize=sizeof(self) class REBARINFO(Structure):
def __init__(self): self.cbSize = sizeof(self) def SetClassName(self, name):
def GetImagelist(self): rbi = REBARINFO(sizeof(REBARINFO), RBIM_IMAGELIST, 0) if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBARINFO, 0, byref(rbi)): raise "could not retrieve imagelist" if rbi.himl: return rbi.himl
def __init__(self): self.cbSize = sizeof(self)
def __init__(self): self.dwSize= sizeof(self)
def __init__(self): self.cbSize=sizeof(self) SIF_RANGE = 1
def GetText(self): p=create_string_buffer(self.GetTextLen()+1) user32.GetWindowTextA(self.Hwnd, p, sizeof(p)) return p.value
def GetText(self): p = create_string_buffer(self.GetTextLen() + 1) user32.GetWindowTextA(self.Hwnd, p, sizeof(p)) return p.value
def CopyData(hwndSource, hwndDest, lp, data, reserved = 0): p= create_string_buffer(SZ_GUID_COPYDATA + data) ## do not include NULL byte in cbData cd= COPYDATASTRUCT(MAKELONG(lp, reserved), sizeof(p) -1, addressof(p)) return bool(user32.SendMessageA(hwndDest, WM_COPYDATA, hwndSource, byref(cd)))
def CopyData(hwndSource, hwndDest, lp, data, reserved=0): p = create_string_buffer(SZ_GUID_COPYDATA + data) ## do not include NULL byte in cbData cd = COPYDATASTRUCT(MAKELONG(lp, reserved), sizeof(p) - 1, addressof(p)) return bool( user32.SendMessageA(hwndDest, WM_COPYDATA, hwndSource, byref(cd)))
def GetTextMax(self): return sizeof(self._client_buffer) - 1
def GetTextMax(self): return sizeof(self._client_buffer) -1
def __init__(self): self.dwSize = sizeof(self)
def __init__(self, cookie, buttons): self.cbSize= sizeof(self) self.type= cookie self.nButtons= len(self.arrButtons) self.arrButtons= buttons self.textBuffer= [None, ]*self.nButtons
def __init__(self): self.cbSize=sizeof(self) class TBADDBITMAP(Structure):