{"id":3703,"date":"2013-07-25T07:00:00","date_gmt":"2013-07-25T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2013\/07\/25\/what-is-the-default-cursor-for-a-thread\/"},"modified":"2013-07-25T07:00:00","modified_gmt":"2013-07-25T07:00:00","slug":"what-is-the-default-cursor-for-a-thread","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20130725-00\/?p=3703","title":{"rendered":"What is the default cursor for a thread?"},"content":{"rendered":"<p>\nWhen we looked at\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2006\/11\/21\/1115695.aspx\">\nthe process by which the cursor is set<\/a>,\nwe neglected to discuss the case where\n<i>nobody bothers to set the cursor<\/i>.\nWhat is the ultimate default cursor?\n<\/p>\n<p>\nLet&#8217;s write a program that refuses to set the cursor.\nTake\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nthe scratch program<\/a>\nand add these lines:\n<\/p>\n<pre>\nBOOL OnSetCursor(HWND hwnd, HWND hwndCursor,\n                 UINT codeHitTest, UINT msg)\n{\n  return TRUE;\n}\n   HANDLE_MSG(hwnd, WM_SETCURSOR, OnSetCursor);\n<\/pre>\n<p>\nWhat we did was make the window explicitly refuse to set\nthe cursor by making it do nothing and return <code>TRUE<\/code>,\nwhich means,\n&#8220;It&#8217;s all good. I set the cursor!&#8221;\n(Liar, liar, pants on fire.)\n<\/p>\n<p>\nRun this program, move the cursor over the window, and what do you get?\n<\/p>\n<p>\nThe hourglass.\n<\/p>\n<p>\nNow, this is clearly some sort of pathological case,\nwhere there is a thread that covers its ears and hums\nwhenever the window manager asks it to specify\na cursor.\nBut you can end up in this case unintentionally,\nand in fact there&#8217;s a good chance that you&#8217;ve seen it happen.\nJust write an application that blocks the UI thread during startup.\nTake a fresh scratch program and add a different line of code:\n<\/p>\n<pre>\n        ShowWindow(hwnd, nShowCmd);\n        <font COLOR=\"blue\">Sleep(5000);<\/font>\n        while (GetMessage(&amp;msg, NULL, 0, 0)) {\n            TranslateMessage(&amp;msg);\n            DispatchMessage(&amp;msg);\n        }\n<\/pre>\n<p>\nHere, we&#8217;re simulating a program that hangs its UI thread\nduring initialization.\nDuring that initial five-second delay,\nthe program has yet to pump any messages,\nso it hasn&#8217;t yet received the\n<code>WM_MOUSE&shy;MOVE<\/code> or\n<code>WM_NC&shy;MOUSE&shy;MOVE<\/code>\nmessage\nthat would normally trigger the\n<code>WM_SET&shy;CURSOR<\/code> message.\nAll the window manager can do is show the default cursor.\n<\/p>\n<p>\nThat&#8217;s why the default cursor is an hourglass.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When we looked at the process by which the cursor is set, we neglected to discuss the case where nobody bothers to set the cursor. What is the ultimate default cursor? Let&#8217;s write a program that refuses to set the cursor. Take the scratch program and add these lines: BOOL OnSetCursor(HWND hwnd, HWND hwndCursor, UINT [&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-3703","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>When we looked at the process by which the cursor is set, we neglected to discuss the case where nobody bothers to set the cursor. What is the ultimate default cursor? Let&#8217;s write a program that refuses to set the cursor. Take the scratch program and add these lines: BOOL OnSetCursor(HWND hwnd, HWND hwndCursor, UINT [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3703","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=3703"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/3703\/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=3703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=3703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=3703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}