[Wnd-commit] wnd/wnd/api copydata.py,NONE,1.1 resources.py,1.3,1.4 win.py,1.2,1.3 winos.py,1.1.1.1,1
Status: Alpha
Brought to you by:
jurner
|
From: jürgen u. <cer...@us...> - 2005-07-23 19:11:28
|
Update of /cvsroot/wnd/wnd/wnd/api In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26340 Modified Files: resources.py win.py winos.py Added Files: copydata.py Log Message: bit of this and a bit of that --- NEW FILE: copydata.py --- from wnd.wintypes import (COPYDATASTRUCT, WNDPROC, user32, sizeof, addressof, byref, c_char, c_int, c_long, c_ulong, LOWORD, HIWORD, WINFUNCTYPE, create_string_buffer) from wnd import fwtypes as fw #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: WM_COPYDATA = 74 ENUMWINDOWSPROC = WINFUNCTYPE(c_int, c_ulong, c_long) #********************************************************************************* #********************************************************************************* class CopyData(object): def __init__(self): self._pWndProc = WNDPROC(self._WndProc) self._pOldWndProc = 0 self._pEnumWindowsProc = ENUMWINDOWSPROC(self._EnumWindowsProc) self._dwResult = c_ulong() self._tmp_result = None self._tmp_GUID = None self._tmp_hwnd = 0 # CopyData helper methods ------------------------------------------------------------- def _EnumWindowsProc(self, hwnd, lp): if self._tmp_result: return 0 # break the loop queryGUID = False if hwnd != self._tmp_hwnd: if lp == 0: # main windows ## query if the window is a framework window result = user32.SendMessageTimeoutA( hwnd, fw.WND_WM_NOTIFY, fw.WND_NM_ISFWWINDOW, self._tmp_hwnd, 2, # SMTO_ABORTIFHUNG 5, # nTimeout byref(self._dwResult)) if result: if self._dwResult.value == fw.WND_MSGRESULT_TRUE: queryGUID = True elif lp== 1: # child windows queryGUID = True if queryGUID: # query window for its GUID user32.SendMessageTimeoutA( hwnd, fw.WND_WM_NOTIFY, fw.WND_NM_GETGUID, self._tmp_hwnd, 2, # SMTO_ABORTIFHUNG 5, # nTimeout byref(self._dwResult)) if not self._tmp_result: ## not result yet... enum childwindows all the way down user32.EnumChildWindows(hwnd, self._pEnumWindowsProc, 1) return 1 def _WndProc(self, hwnd, msg, wp, lp): if msg== WM_COPYDATA: if not self._tmp_result: result= fw.HandleCopyData(hwnd, msg, wp, lp) if result: if HIWORD(result[0]): if LOWORD(result[0])==fw.WND_CD_GUID: if result[1]==self._tmp_GUID: self._tmp_result= wp return 1 return user32.CallWindowProcA(self._pOldWndProc, hwnd, msg, wp, lp) # CopyData methods ---------------------------------------------------------------- def FindGUID(self, hwnd, GUID): self._tmp_hwnd = hwnd self._tmp_GUID = GUID self._tmp_result = None ## subclass the window to catch WM_COPYDATA in response to our query self._pOldWndProc= user32.SetWindowLongA(hwnd, -4, self._pWndProc) if not self._pOldWndProc: raise RuntimeError, "could not subclass window" user32.EnumWindows(self._pEnumWindowsProc, 0) # restore old proc user32.SetWindowLongA(hwnd, -4, self._pOldWndProc) return self._tmp_result def CopyData(self, hwndSource, hwndDest, lp, data, noprefix=False): ## TODO ## what if the window is hung ?? ## can not use timeout here, noone knows how long it will take ## for the window to process the message if noprefix: p= create_string_buffer(data) else: if lp > 0xffff: raise ValueError, "lp must be <= 0xFFFF" p= create_string_buffer(fw.SZ_GUID_COPYDATA + data) ## do not include NULL byte in cbData cd= COPYDATASTRUCT(lp, sizeof(p) -1, addressof(p)) return bool(user32.SendMessageA(hwndDest, WM_COPYDATA, hwndSource, byref(cd))) Index: win.py =================================================================== RCS file: /cvsroot/wnd/wnd/wnd/api/win.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** win.py 2 Jul 2005 08:54:11 -0000 1.2 --- win.py 23 Jul 2005 19:11:19 -0000 1.3 *************** *** 27,39 **** #************************************************* def ToggleTaskBar(): ! try: ! hwnd=user32.FindWindowA('Shell_TrayWnd', 0) if user32.IsWindowVisible(hwnd): ! SW_SHOW = 0 ! user32.ShowWindow(hwnd, SW_SHOW) else: ! SW_HIDE = 5 ! user32.ShowWindow(hwnd, SW_HIDE) ! except: pass def GetText(hwnd): --- 27,41 ---- #************************************************* def ToggleTaskBar(): ! result= None ! ! hwnd= user32.FindWindowA('Shell_TrayWnd', 0) ! if hwnd: if user32.IsWindowVisible(hwnd): ! user32.ShowWindow(hwnd, 0) #SW_HIDE ! result = False else: ! user32.ShowWindow(hwnd, 5) # SW_SHOW ! result= True ! return result def GetText(hwnd): *************** *** 112,116 **** WS_POPUP = 2147483648 GetWindowLong = user32.GetWindowLongA ! GetWindowLong.restype = DWORD style = GetWindowLong(hwnd, GWL_STYLE) if style & WS_POPUP: return True --- 114,118 ---- WS_POPUP = 2147483648 GetWindowLong = user32.GetWindowLongA ! #GetWindowLong.restype = DWORD style = GetWindowLong(hwnd, GWL_STYLE) if style & WS_POPUP: return True Index: resources.py =================================================================== RCS file: /cvsroot/wnd/wnd/wnd/api/resources.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** resources.py 2 Jul 2005 08:54:11 -0000 1.3 --- resources.py 23 Jul 2005 19:11:19 -0000 1.4 *************** *** 137,141 **** # pass ! #def findresource(self, resType, name):7 # if not kernel32.FindResourceA(self.hModule, resType, name): # raise 'cold not locate resource' --- 137,141 ---- # pass ! #def findresource(self, resType, name): # if not kernel32.FindResourceA(self.hModule, resType, name): # raise 'cold not locate resource' *************** *** 149,155 **** - #r = Resources(windll.comctl32) ! #avail= r.ListTypes() #if 'cursor' in avail: --- 149,155 ---- #r = Resources(windll.comctl32) ! #avail= r.ListNames('icon') ! #if 'cursor' in avail: Index: winos.py =================================================================== RCS file: /cvsroot/wnd/wnd/wnd/api/winos.py,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** winos.py 29 Apr 2005 15:19:47 -0000 1.1.1.1 --- winos.py 23 Jul 2005 19:11:19 -0000 1.2 *************** *** 137,141 **** flags = 1 # EWX_SHUTDOWN if force: flags |= 4 | 8 ! if IsNT(): privleges.EnablePrivleges(None, 'SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) --- 137,141 ---- flags = 1 # EWX_SHUTDOWN if force: flags |= 4 | 8 ! if IsNT(): privleges.EnablePrivleges('SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) *************** *** 145,149 **** flags = 2 # EWX_RBOOT if force: flags |= 4 ! if IsNT(): privleges.EnablePrivleges(None, 'SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) --- 145,149 ---- flags = 2 # EWX_RBOOT if force: flags |= 4 ! if IsNT(): privleges.EnablePrivleges('SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) *************** *** 153,157 **** flags = 8 # EWX_POWEROFF if force: flags |= 4 ! if IsNT(): privleges.EnablePrivleges(None, 'SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) --- 153,157 ---- flags = 8 # EWX_POWEROFF if force: flags |= 4 ! if IsNT(): privleges.EnablePrivleges('SeShutdownPrivilege') user32.ExitWindowsEx(flags, 0) |