Hooking windowsmessages with python

K

Kevin Osthoff

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_frame())
win32gui.DragAcceptFiles(hwnd,1)
wnd = win32ui.CreateWindowFromHandle(hwnd)
wnd.HookMessage(self.test,w32con.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_WINDOWPROC 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!
 
A

Aaron Brady

Hi!

I'm trying to set a message hook with python to catch WM_DROPFILES.
The guiframework is Tkinter.
Here a code snippet:


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_WINDOWPROC 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.
 
M

Mike Driscoll

Hi!

I'm trying to set a message hook with python to catch WM_DROPFILES.
The guiframework is Tkinter.
Here a code snippet:


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_WINDOWPROC 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:

http://mail.python.org/mailman/listinfo/python-win32

Mike
 
K

Kevin Osthof

Aaron said:
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. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top