473,699 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!

Nov 20 '08 #1
4 4265
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.
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_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:

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
1273
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 subcalssing in C# / VB.Net (in general .Net)? OR, is there any link in Microsoft sites / MSDN ?
0
1169
by: Jim Hubbard | last post by:
Is GDI Hooking possible in VB.Net?
1
5363
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 works fine). I am also trying to make this project capable of "Rearrange the keyboard" (example type "e" and "K" is sent to the application) by using SendInput function and I am not able to get it to work. I am finding the use of SendInput...
79
5249
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
4480
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. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this: HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as HTMLDocumentEvents2_Event ; DocEvents.oncontextmenu += new...
5
2015
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 same tedium: hooking up events to handlers, and getting data into and out of dialogs. In C++, this is generally handled through code generation and/or macros, but IMO these are brittle and ugly. So my question: Is there a Pythonic way to make...
8
1961
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 hooks. Please (and thankyou), James Randle.
0
3735
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 http://www.ddj.com/184405459?pgno=1 the article presents source code that includes a dll file which holds all the hooking procedures it is written in C++. Is there an implementation for windows api hooking in C# or .NET out
3
989
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 debugging tool!:) Is there a single metaclass who's "__call__" method can be wrapped to do this? TIA, -k
0
8687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8883
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7750
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5874
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.