systemmenu.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fritzchecksum 作者: mementum 项目源码 文件源码
def WndProcManage(wnd):
        if not hasattr(wnd, 'GetHandle'):
            return False

        # Make a dictionary of message names to be used for printing below
        if PRINT_MESSAGES:
            msgdict = dict()
            for name in dir(win32con):
                if name.startswith('WM_'):
                    value = getattr(win32con, name)
                    msgdict[value] = name

        _oldWndProc = win32gui.GetWindowLong(wnd.GetHandle(),
                                             win32con.GWL_WNDPROC)

        def MyWndProc(self, hwnd, msg, wParam, lParam):
            # Display what we've got.
            if PRINT_MESSAGES:
                print (msgdict.get(msg), msg, wParam, lParam)

            # Restore the old WndProc.  Notice the use of win32api
            # instead of win32gui here.  This is to avoid an error due to
            # not passing a callable object.
            if msg == win32con.WM_DESTROY:
                win32api.SetWindowLong(self.GetHandle(),
                                       win32con.GWL_WNDPROC,
                                       _oldWndProc)

            stopproc = False
            for cb, cbtrigger in CALLBACKS[self]:
                if cbtrigger(self, msg, wParam, lParam):
                    if not cb(self, msg, wParam, lParam):
                        stopproc = True
                        break

            if stopproc:
                return
            # Pass all messages (in this case, yours may be different) on to
            # the original WndProc
            return win32gui.CallWindowProc(_oldWndProc,
                                           hwnd, msg,
                                           wParam,
                                           lParam)

        # Bind the function to the passed object
        _newWndProc = MyWndProc.__get__(wnd, wnd.__class__)

        # Set the WndProc to our function
        win32gui.SetWindowLong(wnd.GetHandle(),
                               win32con.GWL_WNDPROC,
                               _newWndProc)
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号