def onMESSAGE(self, hwnd, msg, wp, lp): if msg==fw.WND_WM_NOTIFY: if wp==fw.WND_NM_MSGREFLECT: msgr= fw.WND_MSGREFLECT.from_address(lp) msgr.fReturn= self._base_fMsgReflect if msgr.msg==self.Msg.WM_NOTIFY: nm = NMHDR.from_address(msgr.lParam) if nm.code==self.Msg.NM_CUSTOMDRAW: cd= NMCUSTOMDRAW.from_address(msgr.lParam) result= self.onMSG(hwnd, "customdraw", 0, cd) if result !=None: return result return 0 # CDRF_DODEFAULT elif nm.code==self.Msg.HDN_ITEMCLICK or nm.code==self.Msg.HDN_ITEMCLICKW: nmh = NMHEADER.from_address(msgr.lParam) if nmh.iButton==0: self.onMSG(hwnd, "itemclick", nmh.iItem, 0) elif nm.code==self.Msg.HDN_ITEMDBLCLICK or nm.code==self.Msg.HDN_ITEMDBLCLICKW: nmh = NMHEADER.from_address(msgr.lParam) if nmh.iButton==0: self.onMSG(hwnd, "itemdouble", nmh.iItem, 0) # ...not triggered, on my machine (win98) iButton is allways # zero #if nmh.iButton==0: # self.onMSG(hwnd, "lmbdouble", nmh.iItem, 0) #elif nmh.iButton==1: # self.onMSG(hwnd, "rmbdouble", nmh.iItem, 0) #elif nmh.iButton==2: # self.onMSG(hwnd, "mmbdouble", nmh.iItem, 0) elif nm.code==self.Msg.HDN_BEGINTRACK or nm.code==self.Msg.HDN_BEGINTRACKW: # no further info in NMHEADER self.onMSG(hwnd, "begintrack", 0, 0) elif nm.code==self.Msg.HDN_ENDTRACK: # no further info in NMHEADER self.onMSG(hwnd, "endtrack", 0, 0) return 0 # keyboard non HDS_BUTTON style elif msg==self.Msg.WM_RBUTTONUP: if not self.GetStyleL('style') & self.Style.HDS_BUTTONS: self.onMSG(hwnd, "rmbup", wp, (HIWORD(lp), LOWORD(lp))) elif msg==self.Msg.WM_LBUTTONUP: if not self.GetStyleL('style') & self.Style.HDS_BUTTONS: self.onMSG(hwnd, "lmbup", wp, (HIWORD(lp), LOWORD(lp))) elif msg==self.Msg.WM_LBUTTONDBLCLK: if not self.GetStyleL('style') & self.Style.HDS_BUTTONS: self.onMSG(hwnd, "lmbdouble", wp, (HIWORD(lp), LOWORD(lp))) elif msg==self.Msg.WM_MOUSEACTIVATE: self.onMSG(hwnd, "mouseactivate", 0, 0) elif msg==self.Msg.WM_DESTROY: self.onMSG(hwnd, "destroy", 0, 0)
def onMESSAGE(self, hwnd, msg, wp, lp): if msg == 5: # WM_SIZE ## overwrite to make resizing work if self._base_fIsopen: self.onMSG(hwnd, "size", 0, [0, 0, LOWORD(lp), HIWORD(lp)]) return user32.DefWindowProcA(hwnd, msg, wp, lp)
def onMESSAGE(self, hwnd, msg, wp, lp): if msg == fw.WND_WM_NOTIFY: if wp == fw.WND_NM_MSGREFLECT: msgr = fw.WND_MSGREFLECT.from_address(lp) msgr.fReturn = self._base_fMsgReflect if msgr.msg == self.Msg.WM_COMMAND: notify = HIWORD(msgr.wParam) if notify == self.Msg.EN_CHANGE: self.onMSG(hwnd, "change", 0, 0) elif notify == self.Msg.EN_UPDATE: self.onMSG(hwnd, "update", 0, 0) elif notify == self.Msg.EN_MAXTEXT: self.onMSG(hwnd, "maxtext", 0, 0) elif notify == self.Msg.EN_ERRSPACE: self.onMSG(hwnd, "errspace", 0, 0) return 0 elif msg == self.Msg.WM_CHAR: if wp == VK_RETURN: self.onMSG(hwnd, "return", 0, 0) if not self.GetStyleL('style') & 4096: # ES_WANTRETURN return 0 elif msg == self.Msg.WM_CONTEXTMENU: if self.onMSG(hwnd, "contextmenu", wp, 0): return 0 elif msg == self.Msg.WM_LBUTTONDBLCLK: self.onMSG(hwnd, "lmbdouble", wp, (LOWORD(lp), HIWORD(lp))) elif msg == self.Msg.WM_LBUTTONUP: self.onMSG(hwnd, "lmbup", wp, (LOWORD(lp), HIWORD(lp))) elif msg == self.Msg.WM_RBUTTONUP: result = self.onMSG(hwnd, "rmbup", wp, (LOWORD(lp), HIWORD(lp))) if result == False: return 0 elif msg == self.Msg.WM_SETFOCUS: self.DefWindowProc(hwnd, msg, wp, lp) self.onMSG(hwnd, "setfocus", wp, 0) return 0 elif msg == self.Msg.WM_KILLFOCUS: self.DefWindowProc(hwnd, msg, wp, lp) self.onMSG(hwnd, "killfocus", wp, 0) return 0 elif msg == self.Msg.WM_DESTROY: self.onMSG(hwnd, "destroy", 0, 0)
def GetText(self, i=0): if self.IsSimple(): return ControlMethods.GetText(self) else: if i >= self.__len__(): raise IndexError("index out of range") n = self.SendMessage(self.Hwnd, self.Msg.SB_GETTEXTLENGTH, i, 0) if not n: return '' p = create_string_buffer(LOWORD(n) +1) self.SendMessage(self.Hwnd, self.Msg.SB_GETTEXT, i, p) return p.value
def __init__(self, title, x, y, w, h, *styles): self.Hwnd = 0 self.Msg = dialog_msgs self.Style = dialog_styles #self.Hwnd = 0 self._base_registeredMessages = [] self._base_dragAcceptFiles = False self._base_dialogMode = 'modeless' ## in respect to property sheets ## self._base_timers = [] self._base_debugger = None self._base_guid = None # styles iStyles = self.ParseStyles(styles) self._base_style = [iStyles[3], iStyles[4]] # base/clientstyle # check if debugging is requested and set the windowproc self._base_debugger = fw.GetDebugger(iStyles[3], self.Msg) self._base_pWndProc = WNDPROC(self._base_WndProc) self._base_pOldWndProc = 0 # create a small template clss = 0 helpId = 0 p = [ 1, 0xFFFF, LOWORD(helpId), HIWORD(helpId), LOWORD(iStyles[1]), HIWORD(iStyles[1]), LOWORD(iStyles[0]), HIWORD(iStyles[0]), 0, x, y, w, h, 0, clss ] p += map(ord, title) + [0] if len(p) % 2: p.append(0) self._base_dlgTemplate = buffer((WORD * len(p))(*p))[:]
def IsDialogReflectMessage(hwnd, msg, wp, lp, dlgmode): #print dlgmode ## TODO: test ## filter WM_COMMAND for dialog boxes if msg == 273: # WM_COMMAND #print wp, lp if lp: if dlgmode == 'modeless': return ReflectMessage(hwnd, lp, msg, wp, lp) if lp != 1: # IDOK if lp != 2: # IDCANCEL #DM_GETDEFID = WM_USER + 0 result = user32.SendMessageA(hwnd, 1024, 0, 0) if HIWORD(result) == 21323: # DC_HASDEFID defID = user32.GetDlgItem(hwnd, LOWORD(result)) if defID != lp: return ReflectMessage(hwnd, lp, msg, wp, lp) else: return ReflectMessage(hwnd, lp, msg, wp, lp) elif msg == 276: # WM_HSCROLL if lp: return ReflectMessage(hwnd, lp, msg, wp, lp) elif msg == 277: # WM_VSCROLL if lp: return ReflectMessage(hwnd, lp, msg, wp, lp) elif msg == 78: # WM_NOTIFY nm = NMHDR.from_address(lp) return ReflectMessage(hwnd, nm.hwndFrom, msg, wp, lp) elif msg == 43: # WM_DRAWITEM # NOTE # can not reflect to comboboxes (ODT_COMBOBOX) # they do block all messages here # ?? do it anyway return ReflectMessage(hwnd, user32.GetDlgItem(hwnd, wp), msg, wp, lp) elif msg == 44: # WM_MEASUREITEN # NOTE # can not reflect to comboboxes (ODT_COMBOBOX) # they do block all messages here # ?? do it anyway return ReflectMessage(hwnd, user32.GetDlgItem(hwnd, wp), msg, wp, lp) return None
def ChildProc(self, hwnd, msg, wp, lp): if msg==5: ## WM_SIZE self.onMSG(hwnd, "childsizing", hwnd, [0, 0, LOWORD(lp), HIWORD(lp)]) elif msg==WM_CREATE: self._client_MDIChildren.append(hwnd) self.onMSG(self.Hwnd, "childcreated", hwnd, 0) elif msg==WM_MDIACTIVATE: if self._client_fMessageSend==True: self._client_fMessageSend=False else: self._client_fMessageSend=True self.onMSG(self.Hwnd, "childactivated", lp, wp) elif msg==WM_NCDESTROY: self._client_MDIChildren.remove(hwnd) self.onMSG(self.Hwnd, "childdestroyed", hwnd, 0) return user32.DefMDIChildProcA(hwnd, msg, wp, lp)
def _base_HandleScroll(self, hwnd, msg, wp, lp): oldPos=self.GetPos() code, newPos=LOWORD(wp), HIWORD(wp) nMin, nMax = self.GetRange() if code==SB_ENDSCROLL: newPos, oldPos= oldPos, 0 code='endscroll' elif code==SB_LEFT: newPos=nMin code= msg== self.Msg.WM_VSCROLL and 'up' or 'left' elif code==SB_RIGHT: newPos=nMax code= msg== self.Msg.WM_VSCROLL and 'down' or 'right' elif code==SB_LINELEFT: newPos=oldPos - 1 code= msg== self.Msg.WM_VSCROLL and 'lineup' or 'lineleft' elif code==SB_LINERIGHT: newPos=oldPos + 1 code= msg== self.Msg.WM_VSCROLL and 'linedown' or 'lineright' elif code==SB_PAGELEFT: newPos=oldPos - self.GetPageSize() code= msg== self.Msg.WM_VSCROLL and 'pageup' or 'pageleft' elif code==SB_PAGERIGHT: newPos=oldPos + self.GetPageSize() code= msg== self.Msg.WM_VSCROLL and 'pagedown' or 'pageright' elif code==SB_THUMBPOSITION: newPos=self.GetTrackPos() code='thumbpos' elif code==SB_THUMBTRACK: newPos=self.GetTrackPos() code='thumbtrack' if newPos < nMin: newPos=nMin if newPos > nMax: newPos=nMax msg= self.Msg.WM_VSCROLL and 'vscroll' or 'hscroll' self.onMSG(hwnd, msg, code, (oldPos, newPos)) return 0
def Pageup(self): #SB_PAGEUP = 2 return LOWORD(self.SendMessage(self.Hwnd, self.Msg.EM_SCROLL, 2, 0))
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 GetDefButton(self): DC_HASDEFID = 21323 result = self.SendMessage(self.Hwnd, self.Msg.DM_GETDEFID, 0, 0) if HIWORD(result) == DC_HASDEFID: return user32.GetDlgItem(self.Hwnd, LOWORD(result))
def PosFromChar(self, i): result = self.SendMessage(self.Hwnd, self.Msg.EM_POSFROMCHAR, i, 0) return LOWORD(result), HIWORD(result)
def CharFromPos(self, x, y): result = self.SendMessage(self.Hwnd, self.Msg.EM_CHARFROMPOS, 0, MAKELONG(x, y)) return LOWORD(result)
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 FindXY(self, x, y): result = self.SendMessage(self.Hwnd, self.Msg.LB_ITEMFROMPOINT, 0, MAKELONG(x, y)) if not HIWORD(result): return LOWORD(result)
def DwordToAddress(self, dw): w1, w2= HIWORD(dw), LOWORD(dw) return HIBYTE(w1), LOBYTE(w1), HIBYTE(w2),LOBYTE(w2)
def Linedown(self): #SB_LINEDOWN = 1 return LOWORD(self.SendMessage(self.Hwnd, self.Msg.EM_SCROLL, 1, 0))
def SetRange(self, low=0, high=100): result = self.SendMessage(self.Hwnd, self.Msg.PBM_SETRANGE, 0, MAKELONG(low, high)) return (LOWORD(result), HIWORD(result))
def Pagedown(self): #SB_LINEDOWN= 3 return LOWORD(self.SendMessage(self.Hwnd, self.Msg.EM_SCROLL, 3, 0))
def Lineup(self): #SB_LINEUP = 0 return LOWORD(self.SendMessage(self.Hwnd, self.Msg.EM_SCROLL, 0, 0))
def GetPos(self): result = self.SendMessage(self.Hwnd, self.Msg.UDM_GETPOS, 0, 0) if HIWORD(result): raise RuntimeError("could not retrieve position") return LOWORD(result)
def SetItemSize(self, w, h): result=self.SendMessage(self.Hwnd, self.Msg.TCM_SETITEMSIZE , 0, MAKELONG(w, h)) return LOWORD(result), HIWORD(result)