{"id":111114,"date":"2025-04-24T07:00:00","date_gmt":"2025-04-24T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=111114"},"modified":"2025-04-24T06:44:56","modified_gmt":"2025-04-24T13:44:56","slug":"20250424-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20250424-00\/?p=111114","title":{"rendered":"When I define a window class with no default cursor, what is the explanation for the cursors that appear in my client area?"},"content":{"rendered":"<p>A customer created a window class with no default cursor, meaning that they set the <code>hCursor<\/code> to <code>nullptr<\/code>. What they saw was that the window showed up with an hourglass cursor, and that cursor never went away on its own. But if the user moved the mouse over a border, then the border arrow cursor carried into the client area. What&#8217;s going on?<\/p>\n<p>What&#8217;s going on is that by setting the cursor to <code>nullptr<\/code>, you&#8217;re saying &#8220;I will take care of the cursor.&#8221; Some time ago, I discussed <a title=\"What is the process by which the cursor gets set?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20061121-15\/?p=28943\"> how the cursor gets set<\/a>, and if nobody else takes responsibility, then <code>DefWindowProc<\/code> sets the cursor to the window class&#8217;s registered class cursor.<\/p>\n<p>If there is no registered class cursor (if you set it to <code>nullptr<\/code>), then that final fallback step doesn&#8217;t do anything, and nobody sets the cursor.<\/p>\n<p>If nobody sets the cursor, then the cursor remains unchanged, and whatever cursor is currently set continues to be the cursor. The cursor remains set until somebody else sets a new one. If the cursor wanders over a border, then the <code>Def\u00adWindow\u00adProc<\/code> function sets the border cursor. And then when it wanders into the client area, nobody sets the cursor, so the old border cursor remains.<\/p>\n<p>Nobody actively asked for the border cursor to appear in the client area. Rather, nobody said what they wanted to appear in the client area, so nothing was changed.<\/p>\n<p>The moral of the story is that if you set your class cursor to <code>nullptr<\/code>, then you are assuming responsibility for handling the <code>WM_<wbr \/>SET\u00adCURSOR<\/code> message and making sure that, eventually, somehow, a cursor gets set. If you fail to fulfill that obligation, then nobody sets the cursor, and you get leftover garbage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You said you&#8217;d take care of it, but you didn&#8217;t.<\/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-111114","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You said you&#8217;d take care of it, but you didn&#8217;t.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111114","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=111114"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/111114\/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=111114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=111114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=111114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}