473,379 Members | 1,216 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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_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!

Nov 20 '08 #1
4 4235
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_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!
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.
Nov 20 '08 #2
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_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!
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
Nov 20 '08 #3
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:

http://mail.python.org/mailman/listinfo/python-win32
Ok. I will try this.
Mike
Nov 20 '08 #4
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. ;)
Nov 20 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Raja | last post by:
Dears, I apologize in advance if this is the wrong place to post, sorry for the inconvenience. Is there any book or web site or any kind of resource is available for Windows hooking and...
0
by: Jim Hubbard | last post by:
Is GDI Hooking possible in VB.Net?
1
by: Matthew Kelly | last post by:
I have pulled together a VB.net project that hooks the keyboard (Ref. Paul Kimmel's hooking program) and allow the user to send "mouse right clicks" via the SendInpuut function (mouse emulation...
79
by: pinkfloydhomer | last post by:
I want to scan a file byte for byte for occurences of the the four byte pattern 0x00000100. I've tried with this: # start import sys numChars = 0 startCode = 0 count = 0
3
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events....
5
by: Ryan Ginstrom | last post by:
Apropos recent threads about GUI editors, coming from a Win32/WTL C++ background, I actually like the idea of being able to (easily) create GUIs programmatically. But I still see a lot of the...
8
by: pigeonrandle | last post by:
Hi, Has anyone had any experience with hooking messages in other application windows (like SPY++). I want to listen for WM_MOVE messages, but can only seem to find examples of Keyboard and Mouse...
0
by: joemango | last post by:
Hi everyone, I was just reading the following artilce titled: "Spy: A Windows CE API Interceptor" by Dmitri Leman in Dr. Dobbs Journal, September 02, 2003 located at ...
3
by: Kevin Little | last post by:
In Python 2.4 or 2.5, what is the easiest way to hook any and all callables such that designated code is executed at the very start and end of each call? (Yes, I'm trying to come up with a little...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.