Hooking windowsmessages with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Osthoff

    Hooking windowsmessages with python


    Hi!

    I'm trying to set a message hook with python to catch WM_DROPFILES.
    The guiframework is Tkinter.
    Here a code snippet:
    hwnd = eval(self.wm_fr ame())
    win32gui.DragAc ceptFiles(hwnd, 1)
    wnd = win32ui.CreateW indowFromHandle (hwnd)
    wnd.HookMessage (self.test,w32c on.WM_DROPFILES )
    def test(self):
    print "blala"
    The DragAcceptFiles-Call seems to be alright. When i drag a file over
    the gui there is this drag-and-drop icon. But the problem is, that the
    callback-function (test) is never executed.
    I also try different messages like Mousemove or Buttondown. So i think
    there is a problem with the HookMessage function.
    I read that you must compile Python with PYWIN_WITH_WIND OWPROC option
    enabled. Is this the problem?

    Can someone give me a short working code to hook a message so i can try
    it on my workstation?

    Thx in advance!



  • Aaron Brady

    #2
    Re: Hooking windowsmessages with python

    On Nov 20, 3:52 am, Kevin Osthoff <icepic1...@gmx .dewrote:
    Hi!
    >
    I'm trying to set a message hook with python to catch WM_DROPFILES.
    The guiframework is Tkinter.
    Here a code snippet:
    >
    hwnd = eval(self.wm_fr ame())
    win32gui.DragAc ceptFiles(hwnd, 1)
    wnd = win32ui.CreateW indowFromHandle (hwnd)
    wnd.HookMessage (self.test,w32c on.WM_DROPFILES )
    def test(self):
       print "blala"
    >
    The DragAcceptFiles-Call seems to be alright. When i drag a file over
    the gui there is this drag-and-drop icon. But the problem is, that the
    callback-function (test) is never executed.
    I also try different messages like Mousemove or Buttondown. So i think
    there is a problem with the HookMessage function.
    I read that you must compile Python with PYWIN_WITH_WIND OWPROC option
    enabled. Is this the problem?
    >
    Can someone give me a short working code to hook a message so i can try
    it on my workstation?
    >
    Thx in advance!
    I've done some hooks in C. If no one has a simpler way, I can help
    you build a DLL to do it, and call it from Python.

    Comment

    • Mike Driscoll

      #3
      Re: Hooking windowsmessages with python

      On Nov 20, 3:52 am, Kevin Osthoff <icepic1...@gmx .dewrote:
      Hi!
      >
      I'm trying to set a message hook with python to catch WM_DROPFILES.
      The guiframework is Tkinter.
      Here a code snippet:
      >
      hwnd = eval(self.wm_fr ame())
      win32gui.DragAc ceptFiles(hwnd, 1)
      wnd = win32ui.CreateW indowFromHandle (hwnd)
      wnd.HookMessage (self.test,w32c on.WM_DROPFILES )
      def test(self):
         print "blala"
      >
      The DragAcceptFiles-Call seems to be alright. When i drag a file over
      the gui there is this drag-and-drop icon. But the problem is, that the
      callback-function (test) is never executed.
      I also try different messages like Mousemove or Buttondown. So i think
      there is a problem with the HookMessage function.
      I read that you must compile Python with PYWIN_WITH_WIND OWPROC option
      enabled. Is this the problem?
      >
      Can someone give me a short working code to hook a message so i can try
      it on my workstation?
      >
      Thx in advance!
      I recommend re-posting to the PyWin32 mailing list where the creators
      of this package lurk. They'll probably be able to give you some
      advice:



      Mike

      Comment

      • Kevin Osthof

        #4
        Re: Hooking windowsmessages with python

        Mike Driscoll schrieb:
        I recommend re-posting to the PyWin32 mailing list where the creators
        of this package lurk. They'll probably be able to give you some
        advice:
        >

        >
        Ok. I will try this.
        Mike

        Comment

        • Kevin Osthof

          #5
          Re: Hooking windowsmessages with python

          Aaron Brady wrote:
          I've done some hooks in C. If no one has a simpler way, I can help
          you build a DLL to do it, and call it from Python.
          Thx for the offer but i will try to do it in python first. ;)


          Comment

          Working...