def _base_WndProc(self, hwnd, msg, wp, lp): try: #if msg==fw.WND_WM_NOTIFY: # print 1 # return 0 if self._base_debugger: result= self._base_debugger.HandleMessage(hwnd, msg, wp, lp) if result: self.onMSG(hwnd, "debug", *result) result= fw.IsReflectMessage(hwnd, msg, wp, lp) if result != None: return result result = self.onMESSAGE(hwnd, msg, wp, lp) if result !=None: return result #------------------------------------------------------------------- if msg==43: # WM_DRAWITEM ## ownerdraw menus self.onMSG(hwnd, "drawitem", 0, DRAWITEMSTRUCT.from_address(lp)) return 1 elif msg==44: # WM_MEASUREITEN ## ownerdraw menus self.onMSG(hwnd, "measureitem", 0, MEASUREITEMSTRUCT.from_address(lp)) return 1 elif msg==2: # WM_DESTROY self.onMSG(hwnd, "close", 0, 0) # catch errors ?? # use atexit ?? for i in self._base_timers: user32.KillTimer(hwnd, i) user32.PostQuitMessage(0) return 0 elif msg==self.Msg.WM_NCDESTROY: self.onMSG(hwnd, "destroy", 0, 0) if self._base_Appbar: self._base_Appbar.Close() if self._base_dragAcceptFiles: shell32.DragAcceptFiles(self.Hwnd, 0) if self._base_mutext_singleinst: kernel32.CloseHandle(self._base_mutext_singleinst) return 0 elif msg==self.Msg.WM_QUERYENDSESSION: ENDSESSION_LOGOFF = 2147483648 if lp==ENDSESSION_LOGOFF: fLogoff=True else: fLogoff=False if self.onMSG(hwnd, "close", "endsession", fLogoff)==False: return 1 #return 0 ## have to test on this return 1 elif msg==self.Msg.WM_ENDSESSION: if wp: ENDSESSION_LOGOFF = 2147483648 if lp==ENDSESSION_LOGOFF: fLogoff=True else: fLogoff=False self.onMSG(hwnd, "destroy", "endsession", fLogoff) return 0 elif msg==self.Msg.WM_CONTEXTMENU: self.onMSG(hwnd, "contextmenu",0, 0) return 0 # settings change ---------------------------------------------------------------------------------------- # WM_DEVICECHANGE # WM_DEVMODECHANGE # WM_FONTCHANGE # WM_COMPACTING # WM_INPUTLANGUAGECHANGE # WM_PALETTECHANGED # WM_POWERBROADCAST # WM_QUERYNEWPALETTE # WM_TIMECHANGE # WM_USERCHANGED win9x only # WM_SETTINGCHANGE !! # WM_SYSCOLORCHANGE !! forward to all common controls # lp=(bits/pixel, cxScreen, cyScreen) elif msg==self.Msg.WM_DISPLAYCHANGE: self.onMSG(hwnd, "displaychanged", wp, (LOWORD(lp), HIWORD(lp))) return 0 elif msg==self.Msg.WM_SYSCOLORCHANGE: # forward to all child windows for i in self.ChildWindows(): self.SendMessage(i, msg, wp, lp) self.onMSG(hwnd, "syscolorchanged", 0, 0) return 0 elif msg==self.Msg.WM_FONTCHANGE: self.onMSG(hwnd, "fontchanged", 0, 0) return 0 if msg== fw.WND_WM_TRAY: if lp==self.Msg.WM_MOUSEMOVE: self.onMSG(hwnd, "traymessage", wp, "mousemove") elif lp==self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "lmbdown") elif lp==self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "lmbup") elif lp==self.Msg.WM_LBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "lmbdouble") elif lp==self.Msg.WM_RBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "rmbdown") elif lp==self.Msg.WM_RBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "rmbup") elif lp==self.Msg.WM_RBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "rmbdouble") return 0 elif msg==self.Msg.WM_TIMER: self.onMSG(hwnd, "timer", wp, lp) if self.IsOwnTimer(wp): return 0 elif msg==278: # WM_INITMENU self.onMSG(hwnd, "menu open", wp, 0) elif msg==279: # WM_INITMENUPOPUP if HIWORD(lp): # system menu pass else: # menu self.onMSG(hwnd, "menu popup", wp, 0) elif msg==273: # WM_COMMAND if not lp: if HIWORD(wp): # accelerator message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), True)) else: # menu message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), False)) elif msg==5: # WM_SIZE if self._base_fIsopen: self.onMSG(hwnd, "size", 0, [0, 0, LOWORD(lp), HIWORD(lp)]) elif msg==self.Msg.WM_ENTERSIZEMOVE: self.onMSG(self.Hwnd, "entersizemove", 0, 0) elif msg==self.Msg.WM_EXITSIZEMOVE: self.onMSG(self.Hwnd, "exitsizemove", 0, 0) elif msg==self.Msg.WM_MOUSELEAVE: self.onMSG(self.Hwnd, "mouseleave", wp, lp) elif msg==self.Msg.WM_GETMINMAXINFO: self.onMSG(hwnd, "getminmaxinfo", 0, MINMAXINFO.from_address(lp)) return 0 elif msg==self.Msg.WM_HOTKEY: self.onMSG(hwnd, "hotkey", wp, (HIWORD(lp), LOWORD(lp))) elif msg==self.Msg.WM_SETFOCUS: self.onMSG(hwnd, "setfocus", wp, 0) elif msg==self.Msg.WM_KILLFOCUS: self.onMSG(hwnd, "killfocus", wp, 0) elif msg==self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "lmbup", wp, 0) elif msg==self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "lmbdown", wp, 0) elif msg==self.Msg.WM_DROPFILES: pt=POINT() fClient= shell32.DragQueryPoint(wp, byref(pt)) if fClient: fClient= True else: fClient= False ## get the number of dropped files n= shell32.DragQueryFile(wp, -1, None, 0) p = create_string_buffer(260 +1) # MAX_PATH +1 or not... damn C out=[] for i in range(n): shell32.DragQueryFile(wp, i, p, 260 +1) # MAX_PATH out.append(p.value) shell32.DragFinish(wp) self.onMSG(self.Hwnd, "droppedfiles", (pt.x, pt.y, fClient), out) #--------------------------------------------------- # drag window by its client area # thanks to catch22.net elif msg==132: # WM_NCHITTEST if self.GetStyleL('basestyle') & self.Style.WS_BASE_MOVE: hittest = self.DefWindowProc(hwnd, msg, wp, lp) if hittest == 1: #HTCLIENT return 2 # HTCAPTION return hittest # copydata ------------------------------------------------------- elif msg== self.Msg.WM_COPYDATA: result = fw.HandleCopyData(hwnd, msg, wp, lp) if result == None: return 0 if HIWORD(result[0]): # reserved for framework, must be mislead return 0 if self.onMSG(hwnd, "copydata", wp, (result[0], result[1]))== False: return 0 return 1 # framework messages ------------------------------------------------------- elif msg==fw.WND_WM_NOTIFY: if wp==fw.WND_NM_MENU: mnu= fw.WND_MENU.from_address(lp) if nmu.type==fw.MNUT_MENU: if nmu.code==fw.MNUF_REMOVE: # clears a menu from the menu bar, does not free it. ## TODO: better not raise here, leave it to caller if user32.GetMenu(self.Hwnd)==nmu.handle: if not user32.SetMenu(self.Hwnd, 0): raise RuntimeError, "could not remove menu" if not user32.DrawMenuBar(self.Hwnd): raise RuntimeError, "could not redraw menu bar" return 1 elif nmu.type==fw.MNUT_ACCEL: # remove accelerator table if nmu.code==fw.MNUF_REMOVE: self._base_hAccelerator = 0 return 1 return 0 elif wp== fw.WND_NM_DLGDISPATCH: if lp: self._base_hwndDlgMsg = lp else: self._base_hwndDlgMsg = self.Hwnd elif wp== fw.WND_NM_GETGUID: guid= self.GetGUID() if guid: fw.CopyData(self.Hwnd, lp, fw.WND_CD_GUID, guid, 1) return 1 return 0 elif wp== fw.WND_NM_ISMAINWINDOW: return fw.WND_MSGRESULT_TRUE elif wp== fw.WND_NM_ISFWWINDOW: return fw.WND_MSGRESULT_TRUE elif wp==fw.WND_NM_EXCEPTION: nexc= fw.WND_EXCEPTION.from_address(lp) if nexc.type==fw.EXC_EXCEPTION: fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() elif nexc.type==fw.EXC_FATAL: print "\nsome fatal exception occured, taking down the gui" raise fw.ChildwindowExit() elif nexc.type==fw.EXC_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() return 0 return 0 #-------------------------------------------------- # pass registered messages else: if msg in self._base_registeredMessages: result=self.onMSG(hwnd, msg, wp, lp) if result !=None: return result # default return self.DefWindowProc(hwnd, msg, wp, lp) except Exception, details: if isinstance(details, fw.ChildwindowExit): # child window should have printed exc already import sys sys.exit() else: import traceback traceback.print_exc() fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: user32.PostQuitMessage(fw.EXC_MAXERROR) #print "max error (%s) exceeded, taking down the GUI" % fw.WND_MAXERROR import sys sys.exit() return self.DefWindowProc(hwnd, msg, wp, lp)
def _base_WndProc(self, hwnd, msg, wp, lp): try: if self._base_debugger: result = self._base_debugger.HandleMessage(hwnd, msg, wp, lp) if result: self.onMSG(hwnd, "debug", *result) result = fw.IsDialogReflectMessage(hwnd, msg, wp, lp, self._base_dialogMode) if result != None: return result if msg == self.Msg.WM_INITDIALOG: self.Hwnd = hwnd result = self.onINITDIALOG(hwnd, msg, wp, lp) if result != None: return result return 0 result = self.onMESSAGE(hwnd, msg, wp, lp) if result != None: return result #--------------------------------------------------------------------------- elif msg == self.Msg.WM_ACTIVATE: #WA_INACTIVE = 0 #WA_ACTIVE = 1 #WA_CLICKACTIVE = 2 if self.GetStyleL('basestyle') & self.Style.WS_BASE_DIALOGLIKE: ## tell the mainwindow to dispatch/clear IsDialogMessage hwndMain = self.GetMainWindow() if hwndMain: if LOWORD(wp) & 3: # activated self.SendMessage(hwndMain, fw.WND_WM_NOTIFY, fw.WND_NM_DLGDISPATCH, self.Hwnd) else: self.SendMessage(hwndMain, fw.WND_WM_NOTIFY, fw.WND_NM_DLGDISPATCH, 0) # clear # copydata ------------------------------------------------------- elif msg == self.Msg.WM_COPYDATA: result = fw.HandleCopyData(hwnd, msg, wp, lp) if result == None: return 0 if HIWORD( result[0]): # reserved for framework, must be mislead return 0 if self.onMSG(hwnd, "copydata", wp, (result[0], result[1])) == False: return 0 return 1 ## property sheets elif msg == PSM_QUERYSIBLINGS: result = self.onMSG(hwnd, "prop_querysiblings", wp, lp) if result: return result return 0 elif msg == self.Msg.WM_SYSCOLORCHANGE: ## forward to all child windows for i in self.ChildWindows(): self.SendMessage(i, msg, wp, lp) self.onMSG(hwnd, "syscolorchanged", 0, 0) return 0 elif msg == 278: # WM_INITMENU self.onMSG(hwnd, "menu open", wp, 0) elif msg == 279: # WM_INITMENUPOPUP if HIWORD(lp): # system menu pass else: # menu self.onMSG(hwnd, "menu popup", wp, 0) elif msg == self.Msg.WM_COMMAND: if self._base_dialogMode == 'modal': ## filter out default IDS for 'modal' dialog boxes # we can not set ID of the def button to IDOK # so we have to explicitely test for it if wp == 1 or lp == self.GetDefButton(): # IDOK result = self.onMSG(hwnd, "command", 0, "ok") if result == False: pass elif isinstance(result, (int, long)): self.Close(result) else: self.Close() return 0 if wp == 2: # IDCANCEL result = self.onMSG(hwnd, "command", 0, "cancel") if result == False: pass elif isinstance(result, (int, long)): self.Close(result) else: self.Close() return 0 #if lp: # WM_COMMAND from non framework controls or controls wich # have disabled the message reflect flag, so let them splip if not lp: code = HIWORD(wp) if code == 0: # menu message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), False)) elif code == 1: # accelerator message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), True)) elif msg == fw.WND_WM_TRAY: if lp == self.Msg.WM_MOUSEMOVE: self.onMSG(hwnd, "traymessage", wp, "mousemove") elif lp == self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "lmbdown") elif lp == self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "lmbup") elif lp == self.Msg.WM_LBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "lmbdouble") elif lp == self.Msg.WM_RBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "rmbdown") elif lp == self.Msg.WM_RBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "rmbup") elif lp == self.Msg.WM_RBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "rmbdouble") return 0 elif msg == 5: #WM_SIZE = 5 self.onMSG(hwnd, "size", 0, [0, 0, LOWORD(lp), HIWORD(lp)]) elif msg == self.Msg.WM_ENTERSIZEMOVE: self.onMSG(self.Hwnd, "entersizemove", 0, 0) elif msg == self.Msg.WM_EXITSIZEMOVE: self.onMSG(self.Hwnd, "exitsizemove", 0, 0) elif msg == self.Msg.WM_GETMINMAXINFO: self.onMSG(hwnd, "getminmaxinfo", 0, MINMAXINFO.from_address(lp)) return 0 elif msg == self.Msg.WM_SETFOCUS: self.onMSG(hwnd, "setfocus", wp, 0) elif msg == self.Msg.WM_KILLFOCUS: self.onMSG(hwnd, "killfocus", wp, 0) elif msg == self.Msg.WM_TIMER: self.onMSG(hwnd, "timer", wp, lp) elif msg == self.Msg.WM_DROPFILES: pt = POINT() clientarea = shell32.DragQueryPoint(wp, byref(pt)) if clientarea: clientarea = True else: clientarea = False # get the number of dropped files n = shell32.DragQueryFile(wp, -1, None, 0) MAX_PATH = 260 p = create_string_buffer(MAX_PATH) out = [] for i in range(n): shell32.DragQueryFile(wp, i, p, MAX_PATH) out.append(p.value) shell32.DragFinish(wp) self.onMSG(self.Hwnd, "droppedfiles", (pt.x, pt.y, clientarea), out) # drag window by its client area --------------------------------------------------- ## does not work for dialogs ?? ## #elif msg==132: # WM_NCHITTEST # if self.GetStyleL('basestyle') & self.Style.WS_BASE_MOVE: # hittest = self.DefDlgProc(hwnd, msg, wp, lp) # if hittest == 1: #HTCLIENT # return 2 # HTCAPTION # return hittest ## TODO ## WM_ENDSESSION (...) ?? ## elif msg == self.Msg.WM_CLOSE: self.onMSG(hwnd, "close", 0, 0) elif msg == self.Msg.WM_DESTROY: for i in self._base_timers: user32.KillTimer(hwnd, i) if self._base_dragAcceptFiles: shell32.DragAcceptFiles(self.Hwnd, 0) self._base_dragAcceptFiles = False self.Hwnd = 0 self.onMSG(hwnd, "destroy", 0, 0) elif msg == fw.WND_WM_NOTIFY: if wp == fw.WND_NM_MENU: mnu = fw.WND_MENU.from_address(lp) if nmu.type == fw.MNUT_MENU: if nmu.code == fw.MNUF_REMOVE: # clears a menu from the menu bar, does not free it. ## TODO: better not raise here, leave it to caller if user32.GetMenu(self.Hwnd) == nmu.handle: if not user32.SetMenu(self.Hwnd, 0): raise RuntimeError, "could not remove menu" if not user32.DrawMenuBar(self.Hwnd): raise RuntimeError, "could not redraw menu bar" return 1 elif nmu.type == fw.MNUT_ACCEL: # remove accelerator table if nmu.code == fw.MNUF_REMOVE: self._base_hAccelerator = 0 return 1 return 0 elif wp == fw.WND_NM_GETGUID: guid = self.GetGUID() if guid: fw.CopyData(self.Hwnd, lp, fw.WND_CD_GUID, guid, 1) return 1 return 0 elif wp == fw.WND_NM_EXCEPTION: nexc = fw.WND_EXCEPTION.from_address(lp) if nexc.type == fw.EXC_EXCEPTION: fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() elif nexc.type == fw.EXC_FATAL: print "\nsome fatal exception occured, taking down the gui" raise fw.ChildwindowExit() elif nexc.type == fw.EXC_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() else: if msg in self._base_registeredMessages: result = self.onMSG(hwnd, msg, wp, lp) if result != None: return result # default return 0 except Exception, details: ## TODO ## If an error in a dialog occurs ther is probabbly no need to quit ## the GUI (if there is one). So maybe dialogs should get their own ## MAX_ERROR and stuff if isinstance(details, fw.ChildwindowExit): # child window should have printed exc already import sys sys.exit() else: import traceback traceback.print_exc() fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: user32.PostQuitMessage(fw.EXC_MAXERROR) #print "max error (%s) exceeded, taking down the GUI" % fw.WND_MAXERROR import sys sys.exit() return 0
def _base_WndProc(self, hwnd, msg, wp, lp): try: # if msg==fw.WND_WM_NOTIFY: # print 1 # return 0 if self._base_debugger: result = self._base_debugger.HandleMessage(hwnd, msg, wp, lp) if result: self.onMSG(hwnd, "debug", *result) result = fw.IsReflectMessage(hwnd, msg, wp, lp) if result != None: return result result = self.onMESSAGE(hwnd, msg, wp, lp) if result != None: return result # ------------------------------------------------------------------- if msg == 43: # WM_DRAWITEM ## ownerdraw menus self.onMSG(hwnd, "drawitem", 0, DRAWITEMSTRUCT.from_address(lp)) return 1 elif msg == 44: # WM_MEASUREITEN ## ownerdraw menus self.onMSG(hwnd, "measureitem", 0, MEASUREITEMSTRUCT.from_address(lp)) return 1 elif msg == 2: # WM_DESTROY self.onMSG(hwnd, "close", 0, 0) # catch errors ?? # use atexit ?? for i in self._base_timers: user32.KillTimer(hwnd, i) user32.PostQuitMessage(0) return 0 elif msg == self.Msg.WM_NCDESTROY: self.onMSG(hwnd, "destroy", 0, 0) if self._base_Appbar: self._base_Appbar.Close() if self._base_dragAcceptFiles: shell32.DragAcceptFiles(self.Hwnd, 0) if self._base_mutext_singleinst: kernel32.CloseHandle(self._base_mutext_singleinst) return 0 elif msg == self.Msg.WM_QUERYENDSESSION: ENDSESSION_LOGOFF = 2147483648 if lp == ENDSESSION_LOGOFF: fLogoff = True else: fLogoff = False if self.onMSG(hwnd, "close", "endsession", fLogoff) == False: return 1 # return 0 ## have to test on this return 1 elif msg == self.Msg.WM_ENDSESSION: if wp: ENDSESSION_LOGOFF = 2147483648 if lp == ENDSESSION_LOGOFF: fLogoff = True else: fLogoff = False self.onMSG(hwnd, "destroy", "endsession", fLogoff) return 0 elif msg == self.Msg.WM_CONTEXTMENU: self.onMSG(hwnd, "contextmenu", 0, 0) return 0 # settings change ---------------------------------------------------------------------------------------- # WM_DEVICECHANGE # WM_DEVMODECHANGE # WM_FONTCHANGE # WM_COMPACTING # WM_INPUTLANGUAGECHANGE # WM_PALETTECHANGED # WM_POWERBROADCAST # WM_QUERYNEWPALETTE # WM_TIMECHANGE # WM_USERCHANGED win9x only # WM_SETTINGCHANGE !! # WM_SYSCOLORCHANGE !! forward to all common controls # lp=(bits/pixel, cxScreen, cyScreen) elif msg == self.Msg.WM_DISPLAYCHANGE: self.onMSG(hwnd, "displaychanged", wp, (LOWORD(lp), HIWORD(lp))) return 0 elif msg == self.Msg.WM_SYSCOLORCHANGE: # forward to all child windows for i in self.ChildWindows(): self.SendMessage(i, msg, wp, lp) self.onMSG(hwnd, "syscolorchanged", 0, 0) return 0 elif msg == self.Msg.WM_FONTCHANGE: self.onMSG(hwnd, "fontchanged", 0, 0) return 0 if msg == fw.WND_WM_TRAY: if lp == self.Msg.WM_MOUSEMOVE: self.onMSG(hwnd, "traymessage", wp, "mousemove") elif lp == self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "lmbdown") elif lp == self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "lmbup") elif lp == self.Msg.WM_LBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "lmbdouble") elif lp == self.Msg.WM_RBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "rmbdown") elif lp == self.Msg.WM_RBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "rmbup") elif lp == self.Msg.WM_RBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "rmbdouble") return 0 elif msg == self.Msg.WM_TIMER: self.onMSG(hwnd, "timer", wp, lp) if self.IsOwnTimer(wp): return 0 elif msg == 278: # WM_INITMENU self.onMSG(hwnd, "menu open", wp, 0) elif msg == 279: # WM_INITMENUPOPUP if HIWORD(lp): # system menu pass else: # menu self.onMSG(hwnd, "menu popup", wp, 0) elif msg == 273: # WM_COMMAND if not lp: if HIWORD(wp): # accelerator message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), True)) else: # menu message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), False)) elif msg == 5: # WM_SIZE if self._base_fIsopen: self.onMSG(hwnd, "size", 0, [0, 0, LOWORD(lp), HIWORD(lp)]) elif msg == self.Msg.WM_ENTERSIZEMOVE: self.onMSG(self.Hwnd, "entersizemove", 0, 0) elif msg == self.Msg.WM_EXITSIZEMOVE: self.onMSG(self.Hwnd, "exitsizemove", 0, 0) elif msg == self.Msg.WM_MOUSELEAVE: self.onMSG(self.Hwnd, "mouseleave", wp, lp) elif msg == self.Msg.WM_GETMINMAXINFO: self.onMSG(hwnd, "getminmaxinfo", 0, MINMAXINFO.from_address(lp)) return 0 elif msg == self.Msg.WM_HOTKEY: self.onMSG(hwnd, "hotkey", wp, (HIWORD(lp), LOWORD(lp))) elif msg == self.Msg.WM_SETFOCUS: self.onMSG(hwnd, "setfocus", wp, 0) elif msg == self.Msg.WM_KILLFOCUS: self.onMSG(hwnd, "killfocus", wp, 0) elif msg == self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "lmbup", wp, 0) elif msg == self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "lmbdown", wp, 0) elif msg == self.Msg.WM_DROPFILES: pt = POINT() fClient = shell32.DragQueryPoint(wp, byref(pt)) if fClient: fClient = True else: fClient = False ## get the number of dropped files n = shell32.DragQueryFile(wp, -1, None, 0) p = create_string_buffer(260 + 1) # MAX_PATH +1 or not... damn C out = [] for i in range(n): shell32.DragQueryFile(wp, i, p, 260 + 1) # MAX_PATH out.append(p.value) shell32.DragFinish(wp) self.onMSG(self.Hwnd, "droppedfiles", (pt.x, pt.y, fClient), out) # --------------------------------------------------- # drag window by its client area # thanks to catch22.net elif msg == 132: # WM_NCHITTEST if self.GetStyleL("basestyle") & self.Style.WS_BASE_MOVE: hittest = self.DefWindowProc(hwnd, msg, wp, lp) if hittest == 1: # HTCLIENT return 2 # HTCAPTION return hittest # copydata ------------------------------------------------------- elif msg == self.Msg.WM_COPYDATA: result = fw.HandleCopyData(hwnd, msg, wp, lp) if result == None: return 0 if HIWORD(result[0]): # reserved for framework, must be mislead return 0 if self.onMSG(hwnd, "copydata", wp, (result[0], result[1])) == False: return 0 return 1 # framework messages ------------------------------------------------------- elif msg == fw.WND_WM_NOTIFY: if wp == fw.WND_NM_MENU: mnu = fw.WND_MENU.from_address(lp) if nmu.type == fw.MNUT_MENU: if nmu.code == fw.MNUF_REMOVE: # clears a menu from the menu bar, does not free it. ## TODO: better not raise here, leave it to caller if user32.GetMenu(self.Hwnd) == nmu.handle: if not user32.SetMenu(self.Hwnd, 0): raise RuntimeError, "could not remove menu" if not user32.DrawMenuBar(self.Hwnd): raise RuntimeError, "could not redraw menu bar" return 1 elif nmu.type == fw.MNUT_ACCEL: # remove accelerator table if nmu.code == fw.MNUF_REMOVE: self._base_hAccelerator = 0 return 1 return 0 elif wp == fw.WND_NM_DLGDISPATCH: if lp: self._base_hwndDlgMsg = lp else: self._base_hwndDlgMsg = self.Hwnd elif wp == fw.WND_NM_GETGUID: guid = self.GetGUID() if guid: fw.CopyData(self.Hwnd, lp, fw.WND_CD_GUID, guid, 1) return 1 return 0 elif wp == fw.WND_NM_ISMAINWINDOW: return fw.WND_MSGRESULT_TRUE elif wp == fw.WND_NM_ISFWWINDOW: return fw.WND_MSGRESULT_TRUE elif wp == fw.WND_NM_EXCEPTION: nexc = fw.WND_EXCEPTION.from_address(lp) if nexc.type == fw.EXC_EXCEPTION: fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() elif nexc.type == fw.EXC_FATAL: print "\nsome fatal exception occured, taking down the gui" raise fw.ChildwindowExit() elif nexc.type == fw.EXC_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() return 0 return 0 # -------------------------------------------------- # pass registered messages else: if msg in self._base_registeredMessages: result = self.onMSG(hwnd, msg, wp, lp) if result != None: return result # default return self.DefWindowProc(hwnd, msg, wp, lp) except Exception, details: if isinstance(details, fw.ChildwindowExit): # child window should have printed exc already import sys sys.exit() else: import traceback traceback.print_exc() fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: user32.PostQuitMessage(fw.EXC_MAXERROR) # print "max error (%s) exceeded, taking down the GUI" % fw.WND_MAXERROR import sys sys.exit() return self.DefWindowProc(hwnd, msg, wp, lp)
def _base_WndProc(self, hwnd, msg, wp, lp): try: if self._base_debugger: result= self._base_debugger.HandleMessage(hwnd, msg, wp, lp) if result: self.onMSG(hwnd, "debug", *result) result= fw.IsDialogReflectMessage(hwnd, msg, wp, lp, self._base_dialogMode) if result != None: return result if msg == self.Msg.WM_INITDIALOG: self.Hwnd= hwnd result= self.onINITDIALOG(hwnd, msg, wp, lp) if result != None: return result return 0 result=self.onMESSAGE(hwnd, msg, wp, lp) if result != None: return result #--------------------------------------------------------------------------- elif msg==self.Msg.WM_ACTIVATE: #WA_INACTIVE = 0 #WA_ACTIVE = 1 #WA_CLICKACTIVE = 2 if self.GetStyleL('basestyle') & self.Style.WS_BASE_DIALOGLIKE: ## tell the mainwindow to dispatch/clear IsDialogMessage hwndMain= self.GetMainWindow() if hwndMain: if LOWORD(wp) & 3: # activated self.SendMessage(hwndMain, fw.WND_WM_NOTIFY, fw.WND_NM_DLGDISPATCH, self.Hwnd) else: self.SendMessage(hwndMain, fw.WND_WM_NOTIFY, fw.WND_NM_DLGDISPATCH, 0) # clear # copydata ------------------------------------------------------- elif msg== self.Msg.WM_COPYDATA: result = fw.HandleCopyData(hwnd, msg, wp, lp) if result == None: return 0 if HIWORD(result[0]): # reserved for framework, must be mislead return 0 if self.onMSG(hwnd, "copydata", wp, (result[0], result[1]))== False: return 0 return 1 ## property sheets elif msg==PSM_QUERYSIBLINGS: result= self.onMSG(hwnd, "prop_querysiblings", wp, lp) if result: return result return 0 elif msg==self.Msg.WM_SYSCOLORCHANGE: ## forward to all child windows for i in self.ChildWindows(): self.SendMessage(i, msg, wp, lp) self.onMSG(hwnd, "syscolorchanged", 0, 0) return 0 elif msg==278: # WM_INITMENU self.onMSG(hwnd, "menu open", wp, 0) elif msg==279: # WM_INITMENUPOPUP if HIWORD(lp): # system menu pass else: # menu self.onMSG(hwnd, "menu popup", wp, 0) elif msg==self.Msg.WM_COMMAND: if self._base_dialogMode=='modal': ## filter out default IDS for 'modal' dialog boxes # we can not set ID of the def button to IDOK # so we have to explicitely test for it if wp==1 or lp==self.GetDefButton(): # IDOK result=self.onMSG(hwnd,"command", 0,"ok") if result==False: pass elif isinstance(result, (int, long)): self.Close(result) else: self.Close() return 0 if wp==2: # IDCANCEL result=self.onMSG(hwnd,"command", 0, "cancel") if result==False: pass elif isinstance(result, (int, long)): self.Close(result) else: self.Close() return 0 #if lp: # WM_COMMAND from non framework controls or controls wich # have disabled the message reflect flag, so let them splip if not lp: code= HIWORD(wp) if code==0: # menu message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), False)) elif code==1: # accelerator message self.onMSG(hwnd, "menu choice", user32.GetMenu(self.Hwnd), (LOWORD(wp), True)) elif msg==fw.WND_WM_TRAY: if lp==self.Msg.WM_MOUSEMOVE: self.onMSG(hwnd, "traymessage", wp, "mousemove") elif lp==self.Msg.WM_LBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "lmbdown") elif lp==self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "lmbup") elif lp==self.Msg.WM_LBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "lmbdouble") elif lp==self.Msg.WM_RBUTTONDOWN: self.onMSG(hwnd, "traymessage", wp, "rmbdown") elif lp==self.Msg.WM_RBUTTONUP: self.onMSG(hwnd, "traymessage", wp, "rmbup") elif lp==self.Msg.WM_RBUTTONDBLCLK: self.onMSG(hwnd, "traymessage", wp, "rmbdouble") return 0 elif msg==5: #WM_SIZE = 5 self.onMSG(hwnd, "size", 0, [0, 0, LOWORD(lp), HIWORD(lp)]) elif msg==self.Msg.WM_ENTERSIZEMOVE: self.onMSG(self.Hwnd, "entersizemove", 0, 0) elif msg==self.Msg.WM_EXITSIZEMOVE: self.onMSG(self.Hwnd, "exitsizemove", 0, 0) elif msg==self.Msg.WM_GETMINMAXINFO: self.onMSG(hwnd, "getminmaxinfo", 0, MINMAXINFO.from_address(lp)) return 0 elif msg==self.Msg.WM_SETFOCUS: self.onMSG(hwnd, "setfocus", wp, 0) elif msg==self.Msg.WM_KILLFOCUS: self.onMSG(hwnd, "killfocus", wp, 0) elif msg==self.Msg.WM_TIMER: self.onMSG(hwnd, "timer", wp, lp) elif msg==self.Msg.WM_DROPFILES: pt=POINT() clientarea=shell32.DragQueryPoint(wp, byref(pt)) if clientarea: clientarea=True else: clientarea=False # get the number of dropped files n=shell32.DragQueryFile(wp, -1, None, 0) MAX_PATH=260 p = create_string_buffer(MAX_PATH) out=[] for i in range(n): shell32.DragQueryFile(wp, i, p, MAX_PATH) out.append(p.value) shell32.DragFinish(wp) self.onMSG(self.Hwnd, "droppedfiles", (pt.x, pt.y, clientarea), out) # drag window by its client area --------------------------------------------------- ## does not work for dialogs ?? ## #elif msg==132: # WM_NCHITTEST # if self.GetStyleL('basestyle') & self.Style.WS_BASE_MOVE: # hittest = self.DefDlgProc(hwnd, msg, wp, lp) # if hittest == 1: #HTCLIENT # return 2 # HTCAPTION # return hittest ## TODO ## WM_ENDSESSION (...) ?? ## elif msg==self.Msg.WM_CLOSE: self.onMSG(hwnd, "close", 0, 0) elif msg==self.Msg.WM_DESTROY: for i in self._base_timers: user32.KillTimer(hwnd, i) if self._base_dragAcceptFiles: shell32.DragAcceptFiles(self.Hwnd, 0) self._base_dragAcceptFiles=False self.Hwnd= 0 self.onMSG(hwnd, "destroy", 0, 0) elif msg==fw.WND_WM_NOTIFY: if wp==fw.WND_NM_MENU: mnu= fw.WND_MENU.from_address(lp) if nmu.type==fw.MNUT_MENU: if nmu.code==fw.MNUF_REMOVE: # clears a menu from the menu bar, does not free it. ## TODO: better not raise here, leave it to caller if user32.GetMenu(self.Hwnd)==nmu.handle: if not user32.SetMenu(self.Hwnd, 0): raise RuntimeError, "could not remove menu" if not user32.DrawMenuBar(self.Hwnd): raise RuntimeError, "could not redraw menu bar" return 1 elif nmu.type==fw.MNUT_ACCEL: # remove accelerator table if nmu.code==fw.MNUF_REMOVE: self._base_hAccelerator = 0 return 1 return 0 elif wp== fw.WND_NM_GETGUID: guid= self.GetGUID() if guid: fw.CopyData(self.Hwnd, lp, fw.WND_CD_GUID, guid, 1) return 1 return 0 elif wp==fw.WND_NM_EXCEPTION: nexc= fw.WND_EXCEPTION.from_address(lp) if nexc.type==fw.EXC_EXCEPTION: fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() elif nexc.type==fw.EXC_FATAL: print "\nsome fatal exception occured, taking down the gui" raise fw.ChildwindowExit() elif nexc.type==fw.EXC_MAXERROR: print "\nmax error (%s) exceeded, taking down the gui" % fw.WND_MAXERROR raise fw.ChildwindowExit() else: if msg in self._base_registeredMessages: result=self.onMSG(hwnd, msg, wp, lp) if result !=None: return result # default return 0 except Exception, details: ## TODO ## If an error in a dialog occurs ther is probabbly no need to quit ## the GUI (if there is one). So maybe dialogs should get their own ## MAX_ERROR and stuff if isinstance(details, fw.ChildwindowExit): # child window should have printed exc already import sys sys.exit() else: import traceback traceback.print_exc() fw.WND_ERRORLEVEL += 1 if fw.WND_ERRORLEVEL > fw.WND_MAXERROR: user32.PostQuitMessage(fw.EXC_MAXERROR) #print "max error (%s) exceeded, taking down the GUI" % fw.WND_MAXERROR import sys sys.exit() return 0