{"id":35543,"date":"2005-05-25T09:00:27","date_gmt":"2005-05-25T09:00:27","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/05\/25\/the-effect-of-setcursor-lasts-only-until-the-next-setcursor\/"},"modified":"2005-05-25T09:00:27","modified_gmt":"2005-05-25T09:00:27","slug":"the-effect-of-setcursor-lasts-only-until-the-next-setcursor","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050525-27\/?p=35543","title":{"rendered":"The effect of SetCursor lasts only until the next SetCursor"},"content":{"rendered":"<p>\nOf course the effect of\n<a HREF=\"http:\/\/msdn.microsoft.com\/library\/en-us\/winui\/winui\/windowsuserinterface\/resources\/cursors\/cursorreference\/cursorfunctions\/setcursor.asp\">\nthe <code>SetCursor<\/code> function<\/a>\nfor a thread\nlasts only until that thread changes the cursor to something else.\nAny moron knows that, right?\n<\/p>\n<p>\nThe tricky part is that the <code>SetCursor<\/code> may come from\nan unexpected place.\n<\/p>\n<p>\nTHe most common place people run into this is when they do something\nlike this:\n<\/p>\n<pre>\n\/\/ Put up the hourglass\nHCURSOR hcurPrev = SetCursor(hcurWait);\n... do some processing ...\n\/\/ Restore the original cursor\nSetCursor(hcurPrev);\n<\/pre>\n<p>\nThis puts up the hourglass during the processing.\nBut if you pump messages (or if a function you call pumps messages),\nthen the hourglass will go away and return to the normal arrow.\n<\/p>\n<p>\nThat&#8217;s because when you pump messages, this opens the gates for\nmessages like <code>WM_NCHITTEST<\/code> and <code>WM_SETCURSOR<\/code>.\nThe latter in particular will typically result in the cursor changing,\neither to a cursor selected by the window itself or to the class\ncursor if the message makes it all the way to <code>DefWindowProc<\/code>.\n<\/p>\n<p>\nIf you want to keep the hourglass up even while pumping messages,\nyou need to let the window know that &#8220;If you are asked to set the cursor,\nplease put up an hourglass instead of what you would normally display\nas the cursor.&#8221;  That window would then have to alter its\n<code>WM_SETCURSOR<\/code> handling to take this setting into account.\n<\/p>\n<pre>\ncase WM_SETCURSOR:\n if (ForceHourglass()) {\n   SetCursor(hcurWait);\n   return TRUE;\n }\n ...\n<\/pre>\n<p>\nNote that forcing the hourglass is only the tip of the iceberg.\nEven though the cursor is an hourglass, the window is still active\nand can receive other message, such as mouse clicks and keypresses.\nIf your program is not ready to receive new input during this phase,\nyou need to detect this case and not go into some recursive state\nif the user, say, impatiently clicks the &#8220;Compute!&#8221; button while you\nare still computing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Of course the effect of the SetCursor function for a thread lasts only until that thread changes the cursor to something else. Any moron knows that, right? The tricky part is that the SetCursor may come from an unexpected place. THe most common place people run into this is when they do something like this: [&hellip;]<\/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-35543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Of course the effect of the SetCursor function for a thread lasts only until that thread changes the cursor to something else. Any moron knows that, right? The tricky part is that the SetCursor may come from an unexpected place. THe most common place people run into this is when they do something like this: [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35543","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=35543"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35543\/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=35543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}