views:

523

answers:

0

My window is not receiving WM_GESTURE messages, nor WM_TOUCH messages. According to the msdn touch troubleshooter, I ought to be receiving WM_GESTURE messages unless I have called RegisterTouchWindow, which I have not. My code calls GetSystemMetrics as described in the help page for "Getting started with Windows Touch", and it tells me that touch is available and ready. I am running Windows 7, on a tablet PC.

My code is below (Python 2.6, using wx GUI). When I run it, it prints out lots of dots, showing me that my WndProc is being called, and that it is getting the standard messages. It also shows up WM_TABLET_QUERYSYSTEMGESTURESTATUS, message 716, from time to time. But it never receives message 0x240 nor message 0x119, which I believe (from web searching) are the numbers for WM_TOUCH and WM_GESTURE.

import wx
import ctypes
import win32con
win32con.SM_DIGITIZER = 94
win32con.NID_READY = 0x80
win32con.WM_TOUCH = 0x240
win32con.WM_GESTURE = 0x119

touch_capabilities = ctypes.windll.user32.GetSystemMetrics(win32con.SM_DIGITIZER)
assert touch_capabilities>0, 'Input digitizer does not have touch capabilities'
assert touch_capabilities & win32con.NID_READY > 0, 'Input digitizer is not ready'

standard_messages = [win32con.WM_MOUSEMOVE,win32con.WM_NCHITTEST,win32con.WM_SETCURSOR,win32con.WM_PAINT,
                     win32con.WM_MOUSEACTIVATE,win32con.WM_GETDLGCODE,win32con.WM_LBUTTONDOWN,
                     win32con.WM_LBUTTONUP,win32con.WM_CAPTURECHANGED,win32con.WM_MOUSELEAVE,
                     win32con.WM_NCMOUSEMOVE]

class MyWindow(wx.Frame):
    def __init__(self, **x):
        wx.Frame.__init__(self, **x)
        WndProcType = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.c_long, ctypes.c_int, ctypes.c_int, ctypes.c_int)
        self.newWndProc = WndProcType(self.WndProc)
        self.oldWndProc = ctypes.windll.user32.SetWindowLongW(self.GetHandle(), win32con.GWL_WNDPROC, self.newWndProc)
    def WndProc(self, hWnd, msg, wParam, lParam):
        print ('.' if msg in standard_messages else msg),
        return ctypes.windll.user32.CallWindowProcW(self.oldWndProc, hWnd, msg, wParam, lParam)

app = wx.App(False)
frame = MyWindow(parent=None, id=wx.ID_ANY, title='test touch+gestures')
frame.Show(True)
app.MainLoop()