{"id":105487,"date":"2021-07-28T07:00:00","date_gmt":"2021-07-28T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=105487"},"modified":"2021-07-27T08:02:23","modified_gmt":"2021-07-27T15:02:23","slug":"20220728-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20210728-00\/?p=105487","title":{"rendered":"How can I prevent the mouse from moving in response to touch input?"},"content":{"rendered":"<p>A customer had a program that responded to touch input, but they found that when the user touched the screen, the mouse jumped to the touch point. How can they prevent that?<\/p>\n<p>What you can do is make your program <code>WM_<wbr \/>POINTER<\/code>-aware: Process the various <code>WM_<wbr \/>POINTER<\/code> messages directly, and don&#8217;t let them go to <code>Def\u00adWindow\u00adProc<\/code>. It is the <code>Def\u00adWindow\u00adProc<\/code> function that takes unprocessed pointer messages and turns them into equivalent mouse activity.<\/p>\n<p>You can take our <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20030723-00\/?p=43073\"> scratch program<\/a> and make these changes:<\/p>\n<pre>    case WM_POINTERDOWN:\r\n    case WM_POINTERUPDATE:\r\n    case WM_POINTERUP:\r\n    case WM_POINTERWHEEL:\r\n    case WM_POINTERHWHEEL:\r\n    {\r\n        auto pointerId = GET_POINTERID_WPARAM(wParam);\r\n        POINTER_INPUT_TYPE type;\r\n        if (GetPointerType(pointerId, &amp;type) &amp;&amp; type == PT_MOUSE) {\r\n            return DefWindowProc(hwnd, uiMsg, wParam, lParam);\r\n        }\r\n        \/* here is where you process the pointer message directly *\/\r\n        return 0;\r\n    }\r\n<\/pre>\n<p>This program checks whether the pointer message came from a mouse. If so, then it lets the message go through and be processed normally.\u00b9 Otherwise, it handles the message. Or at least, it <i>would<\/i> handle the message once you replace that comment with code that processes the message.<\/p>\n<p>The mapping between pointer messages and mouse messages is<\/p>\n<table class=\"cp3\" style=\"border-collapse: collapse;\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Pointer<\/th>\n<th>Mouse<\/th>\n<\/tr>\n<tr>\n<td><code>WM_POINTERDOWN<\/code><\/td>\n<td><code>WM_*BUTTONDOWN<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>WM_POINTERUPDATE<\/code><\/td>\n<td><code>WM_MOUSEMOVE<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>WM_POINTERUP<\/code><\/td>\n<td><code>WM_*BUTTONUP<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>WM_POINTERWHEEL<\/code><\/td>\n<td><code>WM_MOUSEWHEEL<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>WM_POINTERHWHEEL<\/code><\/td>\n<td><code>WM_MOUSEHWHEEL<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>There are also corresponding nonclient pointer and mouse messages, but I&#8217;m going to let those be processed normally so you can use touch to drag the window by its title bar.<\/p>\n<p>\u00b9 Mouse messages by default don&#8217;t even come in as <code>WM_POINTER<\/code> messages, but you can change that with <code>Enable\u00adMouse\u00adIn\u00adPointer<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You need to make your program pointer-aware.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-105487","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You need to make your program pointer-aware.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=105487"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/105487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=105487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=105487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=105487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}