[python-win32] window events via SetWindowsHookExA
Antoine Martin
antoine at nagafix.co.uk
Thu Sep 17 21:14:33 CEST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
Hi,
I am trying to use SetWindowsHookExA via ctypes to be notified when
Windows are mapped/unmapped, to get the same functionality as
SUBSTRUCTURE_MASK events on the root X-window (or is there a better way
that I have missed?)
Here is the code:
WIN_HOOK = CFUNCTYPE(c_long, c_int, c_uint, c_long)
def register_hook()
WH_CALLWNDPROCRET = 4
dll_handle = ctypes.windll.user32._handle
self.call_next_hook = ctypes.windll.user32.CallNextHookEx
self.hook_handle =
types.windll.user32.SetWindowsHookExA(WH_CALLWNDPROCRET,
WIN_HOOK(window_hook), dll_handle, 0)
def window_hook(self, nCode, wParam, lParam):
print "hello"
return self.call_next_hook(self.hook_handle, nCode, wParam, lParam)
Something with the callback signature must be wrong because the hook
does get registered (hook_handle>0), but as soon as a window event
fires, my application is terminated. It does not even get to say hello...
Here's what I used to figure out the C method signature:
http://msdn.microsoft.com/en-us/library/ms644960(VS.85).aspx
Apologies if this is not the right list (please let me know which one
is), it definitely looks like people here are most likely to be able to
help me.
Thanks
Antoine
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEAREKAAYFAkqyipIACgkQGK2zHPGK1rsYnACfSmX8S99kF0JZbvjRAeFSMAGU
hIMAniBF8mbW3/9xbhSU3zD0c+xluf/p
=rWxJ
-----END PGP SIGNATURE-----
More information about the python-win32
mailing list