def CreateExclusionName(name, flag): from wnd.api import winos if winos.IsNT(): if flag=='desktop': ## create a name exclusive to the current desktop #UOI_NAME = 2 hDesk= user32.GetThreadDesktop(kernel32.GetCurrentThreadId()) dwLen= c_ulong() user32.GetUserObjectInformationA(hDesk, 2, None, 0, byref(dwLen)) p = create_string_buffer('', size=dwLen.value) if user32.GetUserObjectInformationA(hDesk, 2, p, dwLen.value, byref(dwLen)): name = '%s-%s' % (name, p.value) user32.CloseDesktop(hDesk) return name elif flag== 'session': ## create a name exclusive to the current session from wnd.api import privleges try: st= privleges.GetTokenStats(None) name = '%s-%s' % (name, st.AuthenticationId) except: pass return name elif flag == 'trustee': ## create a name exclusive to the current, well trustee that is. import os domain= os.getenv('USERDOMAIN') if domain: return '%s-%s' % (name, domain) # default return name
def __init__(self, size='small'): GPA = kernel32.GetProcAddress isNT = winos.IsNT() if isNT: ## ?? check what happens on successive inits ## should be the same handle returned, at least I hope so GPA.restype = WINFUNCTYPE(BOOL, BOOL) try: IconInit = GPA(shell32._handle, 660) IconInit(1) except: raise RuntimeError, "could not retrieve IconInit api" GPA.restype = WINFUNCTYPE(INT, POINTER(HANDLE), POINTER(HANDLE)) try: SH_GetImageLists = GPA(shell32._handle, 71) except: raise RuntimeError, "could not retrieve shell_GetImageLists api" small = HANDLE() large = HANDLE() if not SH_GetImageLists(byref(large), byref(small)): raise RuntimeError, "could not retrieve system imagelist" if not (large.value and small.value): raise RuntimeError, "could not retrieve system imagelist" if size == 'small': self.handle = small.value else: self.handle = large.value
def __init__(self, size='small'): GPA = kernel32.GetProcAddress isNT= winos.IsNT() if isNT: ## ?? check what happens on successive inits ## should be the same handle returned, at least I hope so GPA.restype = WINFUNCTYPE(BOOL, BOOL) try: IconInit = GPA(shell32._handle, 660) IconInit(1) except: raise RuntimeError, "could not retrieve IconInit api" GPA.restype = WINFUNCTYPE(INT, POINTER(HANDLE), POINTER(HANDLE)) try: SH_GetImageLists = GPA(shell32._handle, 71) except: raise RuntimeError, "could not retrieve shell_GetImageLists api" small = HANDLE() large = HANDLE() if not SH_GetImageLists(byref(large), byref(small)): raise RuntimeError, "could not retrieve system imagelist" if not (large.value and small.value): raise RuntimeError, "could not retrieve system imagelist" if size=='small': self.handle= small.value else: self.handle= large.value
def GetTextExtendM(self, *text): hDC = user32.GetDC(self.Hwnd) if hDC: WM_GETFONT = 49 hFont = self.SendMessage(self.Hwnd, WM_GETFONT, 0, 0) if hFont: hOldFont = gdi32.SelectObject(hDC, hFont) rc = RECT() DT_CALCRECT = 1024 maxL, maxT, maxR, maxB = 0, 0, 0, 0 for i in text: result = user32.DrawTextA(hDC, i, len(i), byref(rc), DT_CALCRECT) maxL, maxT, maxR, maxB = max(maxL, rc.left), max( maxT, rc.top), max(maxR, rc.right), max(maxB, rc.bottom) if not result: if hFont: gdi32.SelectObject(hDC, hOldFont) user32.ReleaseDC(self.Hwnd, hDC) raise RuntimeError( "could not retrieve text extend") # WinError NT only user32.ReleaseDC(self.Hwnd, hDC) if hFont: gdi32.SelectObject(hDC, hOldFont) return maxR - maxL, maxB - maxT return rc.right - rc.left, rc.bottom - rc.top else: raise RuntimeError( "could not retrieve device context") # WinError NT only
def SetItemImage(self, i, iImage): hd = HDITEM() hd.mask = hd.HDI_IMAGE hd.iImage= iImage if self.SendMessage(self.Hwnd, self.Msg.HDM_SETITEM, i, byref(hd)): return hd.iImage raise RuntimeError("could not set irtem image")
def HilightItem(self, i): tci = TCITEM() tci.mask = tci.TCIF_STATE tci.dwStateMask= 2 # TCIS_HIGHLIGHTED tci.dwState= 2 if not self.SendMessage(self.Hwnd, self.Msg.TCM_SETITEM, i, byref(tci)): raise RuntimeError("could set text")
def SetBandChild(self, ID, Control): bi=REBARBANDINFO() bi.fMask = RBBIM_CHILD bi.hwndChild=Control.Hwnd if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band child"
def SetBandMaximizedWidth(self, ID, n): bi=REBARBANDINFO() bi.cxIdeal = n bi.fMask |= RBBIM_IDEALSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band maximized size"
def GetBandBackgroundImage(self, ID): bi=REBARBANDINFO() bi.fMask |= RBBIM_BACKGROUND if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band background image" if bi.hbmBack: return bi.hbmBack
def IndexToID(self, i): bi=REBARBANDINFO() bi.fMask = RBBIM_ID if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, i, byref(bi)): raise "could retrieve band ID" return bi.wID
def SetBandImage(self, ID, i): bi = REBARBANDINFO() bi.fMask = RBBIM_IMAGE bi.iImage = i if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band image"
def GetBandBackgroundImage(self, ID): bi = REBARBANDINFO() bi.fMask |= RBBIM_BACKGROUND if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band background image" if bi.hbmBack: return bi.hbmBack
def SetBandBackgroundImage(self, ID, Bitmap): bi = REBARBANDINFO() bi.fMask = RBBIM_BACKGROUND bi.hbmBack = Bitmap.handle if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band background image"
def GetBandColors(self, ID): bi = REBARBANDINFO() bi.fMask = RBBIM_COLORS if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band colors" return bi.clrFore, bi.clrBack
def SetBandTitle(self, ID, title): bi = REBARBANDINFO() bi.fMask = RBBIM_TEXT bi.lpText = self._client_TruncText(title) if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band title"
def IndexToID(self, i): bi = REBARBANDINFO() bi.fMask = RBBIM_ID if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, i, byref(bi)): raise "could retrieve band ID" return bi.wID
def GetVisibleMonthRange(self): st1 = SYSTEMTIME() st2 = SYSTEMTIME() arrSt = (SYSTEMTIME * 2)(st1, st2) result = self.SendMessage(self.Hwnd, self.Msg.MCM_GETMONTHRANGE, GMR_VISIBLE, byref(arrSt)) return result, st1, st2
def GetVertScrollInfo(Window): sci=SCROLLINFO() sci.fMask=SIF_ALL if not user32.GetScrollInfo(Window.Hwnd, SB_VERT, byref(sci)): raise RuntimeError("could not retrieve vert scrollinfo") return sci.nMin, sci.nMax, sci.nPage, sci.nPos, sci.nTrackPos
def GetBandControlSize(self, ID): bi = REBARBANDINFO() bi.fMask = RBBIM_CHILDSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band control size" return bi.cxMinChild, bi.cyMinChild
def GetBandColors(self, ID): bi=REBARBANDINFO() bi.fMask = RBBIM_COLORS if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band colors" return bi.clrFore, bi.clrBack
def GetBandMaximizedWidth(self, ID): bi = REBARBANDINFO() bi.fMask |= RBBIM_IDEALSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band maximized size" return bi.cxIdeal
def GetBandControlSize(self, ID): bi=REBARBANDINFO() bi.fMask = RBBIM_CHILDSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band control size" return bi.cxMinChild, bi.cyMinChild
def SetBandMaximizedWidth(self, ID, n): bi = REBARBANDINFO() bi.cxIdeal = n bi.fMask |= RBBIM_IDEALSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band maximized size"
def SetBandHeaderSize(self, ID, n): bi=REBARBANDINFO() bi.cxHeader = n bi.fMask |= RBBIM_HEADERSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band header size"
def GetBandHeaderSize(self, ID): bi = REBARBANDINFO() bi.fMask |= RBBIM_HEADERSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band header size" return bi.cxHeader
def SetBandLparam(self, ID, lp): bi=REBARBANDINFO() bi.lParam = lp bi.fMask = RBBIM_LPARAM if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band lParam"
def SetBandHeaderSize(self, ID, n): bi = REBARBANDINFO() bi.cxHeader = n bi.fMask |= RBBIM_HEADERSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band header size"
def SetItemLparam(self, i, lp): hd = HDITEM() hd.mask = hd.HDI_LPARAM hd.lParam= lp if self.SendMessage(self.Hwnd, self.Msg.HDM_SETITEM, i, byref(hd)): return hd.lParam raise RuntimeError("could not set lParam")
def GetBandChild(self, ID): bi = REBARBANDINFO() bi.fMask = RBBIM_CHILD if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band child" if bi.hwndChild: return bi.hwndChild
def SetItemWidth(self, i, n): hd = HDITEM() hd.mask = hd.HDI_WIDTH hd.cxy= n if self.SendMessage(self.Hwnd, self.Msg.HDM_SETITEM, i, byref(hd)): return hd.iImage raise RuntimeError("could not set item width")
def SetBandChild(self, ID, Control): bi = REBARBANDINFO() bi.fMask = RBBIM_CHILD bi.hwndChild = Control.Hwnd if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band child"
def GetTime(self): st=SYSTEMTIME() result= self.SendMessage(self.Hwnd, self.Msg.DTM_GETSYSTEMTIME, 0, byref(st)) if result==GDT_ERROR: raise "could not retrive time" if result==GDT_VALID: return st
def SetBandWidth(self, ID, n): bi = REBARBANDINFO() bi.fMask = RBBIM_SIZE bi.cx = n if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band width"
def GetMonthRange(self, visible=True): st1 = SYSTEMTIME() st2 = SYSTEMTIME() arrSt = (SYSTEMTIME * 2)(st1, st2) result = self.SendMessage(self.Hwnd, self.Msg.MCM_GETMONTHRANGE, GMR_DAYSTATE, byref(arrSt)) return result, st1, st2
def SetBandLparam(self, ID, lp): bi = REBARBANDINFO() bi.lParam = lp bi.fMask = RBBIM_LPARAM if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band lParam"
def GetAreaTipText(self, Control, ID): ti = TOOLINFO() ti.hwnd = Control.Hwnd ti.uId = ID ti.lpszText= addressof(self._client_buffer) self.SendMessage(self.Hwnd, self.Msg.TTM_GETTEXT, 0, byref(ti)) return self._client_buffer.value
def SetAreaTipText(self, Control, ID, text): ti = TOOLINFO() ti.uFlags = TTF_SUBCLASS ti.hwnd = Control.Hwnd ti.uId = ID ti.lpszText = self._client_TruncText(text) self.SendMessage(self.Hwnd, self.Msg.TTM_UPDATETIPTEXT, 0, byref(ti))
def SetBandTitle(self, ID, title): bi=REBARBANDINFO() bi.fMask = RBBIM_TEXT bi.lpText = self._client_TruncText(title) if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band title"
def GetAreaTipText(self, Control, ID): ti = TOOLINFO() ti.hwnd = Control.Hwnd ti.uId = ID ti.lpszText = addressof(self._client_buffer) self.SendMessage(self.Hwnd, self.Msg.TTM_GETTEXT, 0, byref(ti)) return self._client_buffer.value
def SetBandBackgroundImage(self, ID, Bitmap): bi=REBARBANDINFO() bi.fMask = RBBIM_BACKGROUND bi.hbmBack=Bitmap.handle if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band background image"
def __init__(self, hwndParent, hMenu, x, y, w, h, *styles): self.Msg= Msgs self.Style= Styles self.pChildProc= WNDPROC(self.ChildProc) self._client_fMessageSend= False self._client_MDIChildren= [] iStyles = self.ParseStyles(styles, style=1073741824|268435456|33554432|67108864) self._base_style = [iStyles[3], iStyles[4]] # base/clientstyle cs= CLIENTCREATESTRUCT(hMenu, fw.WND_ID_MDICHILD_MIN) # create the MDI-client ## default WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN| ## WS_CLIPSIBLINGS|WS_HSCROLL|WS_VSCROLL #iStyles= 1073741824|268435456|33554432|67108864|1048576|2097152 hwnd=user32.CreateWindowExA( iStyles[1],"mdiclient",'',iStyles[0], x,y,w,h, hwndParent,fw.ID.New(),0,byref(cs)) if not hwnd: raise "could not create MDIFrame" control.ControlFromHandle.__init__(self, hwnd, 'nosubclass')
def SetBandImage(self, ID, i): bi=REBARBANDINFO() bi.fMask = RBBIM_IMAGE bi.iImage=i if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band image"
def SetParts(self, *parts): if len(parts) > 255: raise RuntimeError("too many parts") n = len(parts) arr = (c_int * n)(*parts) if not self.SendMessage(self.Hwnd, self.Msg.SB_SETPARTS, n, byref(arr)): raise RuntimeError("could not set parts")
def GetBandMaximizedWidth(self, ID): bi=REBARBANDINFO() bi.fMask |= RBBIM_IDEALSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band maximized size" return bi.cxIdeal
def Write(self): self.stream = IStreamImpl() result =comctl32.ImageList_Write(self.handle, byref(self.stream.IStream)) del self.stream.IStream if not result: raise RuntimeError("could not write imagelist") #self.stream = None return self.stream.data
def GetBandHeaderSize(self, ID): bi=REBARBANDINFO() bi.fMask |= RBBIM_HEADERSIZE if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band header size" return bi.cxHeader
def __init__(self, bytes): self.stream = IStreamImpl(bytes) handle = comctl32.ImageList_Read(byref(self.stream.IStream)) if not handle: raise RuntimeError("could not create imagelist from bytes") DisposableImagelist.__init__(self, handle) del self.stream.IStream del self.stream
def GetBandChild(self, ID): bi=REBARBANDINFO() bi.fMask = RBBIM_CHILD if not self.SendMessage(self.Hwnd, self.Msg.RB_GETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could retrieve band child" if bi.hwndChild: return bi.hwndChild
def GetMonthRange(self, visible=True): st1=SYSTEMTIME() st2=SYSTEMTIME() arrSt=(SYSTEMTIME*2)(st1, st2) result=self.SendMessage(self.Hwnd, self.Msg.MCM_GETMONTHRANGE, GMR_DAYSTATE, byref(arrSt)) return result, st1, st2
def SetBandWidth(self, ID, n): bi=REBARBANDINFO() bi.fMask = RBBIM_SIZE bi.cx = n if not self.SendMessage(self.Hwnd, self.Msg.RB_SETBANDINFO, self.IDToIndex(ID), byref(bi)): raise "could set band width"
def IsPushed(self, i): tci = TCITEM() tci.mask = tci.TCIF_STATE tci.dwStateMask= 1 # TCIS_BUTTONPRESSED if not self.SendMessage(self.Hwnd, self.Msg.TCM_GETITEM, i, byref(tci)): raise RuntimeError("could retrieve item info") return bool(tci.dwState)
def HitTest(self): pt = POINT() if not user32.GetCursorPos(byref(pt)): raise WinError(GetLastError()) hittest = self.DefWindowProc(self.Hwnd, self.Msg.WM_NCHITTEST, 0, MAKELONG(pt.x, pt.y)) try: return HT_FLAGS[hittest] except: return 'unknown'
def IsHilighted(self, i): tci = TCITEM() tci.mask = tci.TCIF_STATE tci.dwStateMask= 2 # TCIS_HIGHLIGHTED if not self.SendMessage(self.Hwnd, self.Msg.TCM_GETITEM, i, byref(tci)): raise RuntimeError("could retrieve item info") return bool(tci.dwState)
def GetVisibleMonthRange(self): st1=SYSTEMTIME() st2=SYSTEMTIME() arrSt=(SYSTEMTIME*2)(st1, st2) result=self.SendMessage(self.Hwnd, self.Msg.MCM_GETMONTHRANGE, GMR_VISIBLE, byref(arrSt)) return result, st1, st2
def PushItem(self, i): tci = TCITEM() tci.mask = tci.TCIF_STATE tci.dwStateMask= 1 # TCIS_BUTTONPRESSED tci.dwState= 1 if not self.SendMessage(self.Hwnd, self.Msg.TCM_SETITEM, i, byref(tci)): raise RuntimeError("could push item")