1

I'm experimenting with WM_TOUCH messages to capture touch events in my application. I want to register for example a "3 Finger Swipe" gesture and because that was not given in the WM_GESTURE I started experimenting with WM_TOUCH. I found this example http://msdn.microsoft.com/en-us/library/windows/desktop/dd940546%28v=vs.85%29.aspx The problem with the example is, that they use WndProc which only works for individual forms. I want to catch the touches in my whole application, so I tried to use PreFilterMessage instead of WndProc.

    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    public bool PreFilterMessage(ref Message m)
    {
        // Decode and handle WM_TOUCH message.
        bool handled;
        switch (m.Msg)
        {
            case WM_TOUCH:
                Debug.WriteLine("PreFilter TOUCH: " + m.ToString());
                handled = DecodeTouch(ref m);
                break;
            case 0x201:
                Debug.WriteLine("PreFilter LEFTMOUSEDOWN: " + m.ToString());
                handled = false;
                break;
            default:
                handled = false;
                break;
        }
...

The Problem now is, that the LParam in PreFilterMessage is different from the LParam in WndProc which leads to problems when i try to call GetTouchInputInfo. Here is my Debug log:

PreFilter TOUCH: msg=0x240 hwnd=0x530598 wparam=0x1 lparam=0x3ff0573 result=0x0
WndProc TOUCH: msg=0x240 hwnd=0x530598 wparam=0x1 lparam=0xf170000 result=0x0

PreFilter LEFTMOUSEDOWN: msg=0x201 (WM_LBUTTONDOWN) hwnd=0x530598 wparam=0x1 lparam=0x14100c1 result=0x0
WndProc LEFTMOUSEDOWN: msg=0x201 (WM_LBUTTONDOWN) hwnd=0x530598 wparam=0x1 lparam=0x14100c1 result=0x0

Why are the LParam for the mouseinput the same, and for the touchinput different? How can I convert the LParam in PreFilterMessage so that I can call GetTouchInputInfo?

KArlk.
  • 39
  • 1
  • 9
  • this will be a wild guess, so I'm placing it in the comment: check if WM_NCHITTEST doesn't return HTTRANSPARENT somewhere around the time the touch is handled ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms645618(v=vs.85).aspx ). That may be the couse of the difference between PreFilterMessages and WndProc. msdn says that "WM_TOUCH messages do not respect HTTRANSPARENT regions of windows. If a window returns HTTRANSPARENT in response to a WM_NCHITTEST message, mouse messages go to the parent, and WM_TOUCH messages go directly to the window." – Arie Dec 09 '14 at 12:59
  • There is nothing inside Winforms that would cause Message.LParam to change like that. Passing the message by *ref* to DecodeTouch() is fairly suspicious. Only thing that makes sense is that your code is modifying it. Or your window got subclassed by some kind of DLL that was injected into your program, that's technically possible as well. But that would misbehave the same way without IMessageFilter. – Hans Passant Dec 09 '14 at 13:30
  • @Arie I have added a case for the hittest messages as follows `case 0x0084: Debug.WriteLine("HITTEST_W: " + m.Result); handled = false; break;` but the result is always 0. – KArlk. Dec 09 '14 at 13:47
  • After a lot of testing i found some constants; the `LParam` in the `WndProc` always start (at application start) at 0xf110000. For every new message 30.000 gets added. Meanwhile the `LParam` in `PreFilterMessage` seem to be quite random. There have to be some internal functions that are done before the `WndProc` gets the values that aren't done before `PreFilterMessage`. Is there maybe another way to catch the messages before they are passed on to the forms? – KArlk. Dec 09 '14 at 15:46
  • @HansPassant My project is a modified version of the MTScratchpadWMTouch sample that comes with the windows 7 sdk. The sample itself works like it should and is not influenced by my code at all. The `LParam` that end up in `WndProc` are actualy the ones that work fine. I want the same `LParam` in my `PreFilter` so that i can handle touch inputs on the whole application and not just on separate forms. Something modifies the `LParam` before they get to `WndProc` and I need to find out what that is to use it myself. – KArlk. Dec 10 '14 at 10:29

1 Answers1

0

I ended up using a different approach since i could not get this to work. I used a transparent form as an overlay (like this) to get the correct Message. This way I got the right LParam. Also I could forward the Message to the window below the overlay by using CallWindowProc with a modified hWnd, if I need to.

Community
  • 1
  • 1
KArlk.
  • 39
  • 1
  • 9