{"id":93685,"date":"2016-06-16T07:00:00","date_gmt":"2016-06-16T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=93685"},"modified":"2019-03-13T11:51:06","modified_gmt":"2019-03-13T18:51:06","slug":"20160616-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20160616-00\/?p=93685","title":{"rendered":"Why do I get a spurious WM_MOUSEMOVE message whenever Resource Manager is running?"},"content":{"rendered":"<p>We saw some time ago that the operating system generates spurious <code>WM_MOUSE&shy;MOVE<\/code> messages <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20031001-00\/?p=42343\">as a side effect of mouse cursor recalculations<\/a>. In a sense, the way to kick-start a mouse cursor recalculation is to pretend that the mouse moved. And if you see a continuous stream of spurious <code>WM_MOUSE&shy;MOVE<\/code> messages, then it suggests that there is <a HREF=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/\">some continuous activity<\/a> that is triggering mouse cursor recalculation. <\/p>\n<p>A customer discovered that their program receive spurious <code>WM_MOUSE&shy;MOVE<\/code> messages at a rate of approximately one every two seconds. They were able to narrow down the conditions and found that it occurred when the Hyper-V Manager or Resource Monitor were running. What is it about those two programs that is causing all the spurious mouse activity? <\/p>\n<p>The common thread is that these program have a continuously updating window that refreshes (you guessed it) every two seconds. At each refresh, the programs do a <code>WM_SET&shy;REDRAW<\/code> to disable redrawing in their window, then they update all their stuff, and then they do another <code>WM_SET&shy;REDRAW<\/code> to re-enable redrawing. <\/p>\n<p>We saw some time ago that <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20110124-00\/?p=11683\">the window manager provides a default implementation of the <code>WM_SET&shy;REDRAW<\/code> message<\/a> which makes the window pseudo-invisible when redraw is disabled, and then undoes all the weird fakery when redraw is re-enabled. <\/p>\n<p>Undoing the weird fakery is where the spurious <code>WM_MOUSE&shy;MOVE<\/code> messages are coming from. Making a window pseudo-visible means, among other things, that if the cursor is inside the window that just became pseudo-visible, the window needs to be told, &#8220;Hey, you have the mouse cursor. Set the cursor to something appropriate.&#8221; <\/p>\n<p>And that&#8217;s what&#8217;s triggering the spurious mouse move messages every two seconds. <\/p>\n<p>If processing mouse-move messages is expensive for your program, you can watch to see if you receive a mouse move message that matches the coordinates of the previous message. If so, and your program state hasn&#8217;t changed between the two messages, then ignore the spurious message. (Of course, if your program state <i>has<\/i> changed, then you will want to reprocess the message, because the answer to the question might be different the second time around.) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>An artifact of certain window manager operations.<\/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-93685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>An artifact of certain window manager operations.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93685","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=93685"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/93685\/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=93685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=93685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=93685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}