{"id":11563,"date":"2011-02-07T07:00:00","date_gmt":"2011-02-07T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2011\/02\/07\/the-cursor-isnt-associated-with-a-window-or-a-window-class-its-associated-with-a-thread-group\/"},"modified":"2011-02-07T07:00:00","modified_gmt":"2011-02-07T07:00:00","slug":"the-cursor-isnt-associated-with-a-window-or-a-window-class-its-associated-with-a-thread-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20110207-00\/?p=11563","title":{"rendered":"The cursor isn&#039;t associated with a window or a window class; it&#039;s associated with a thread group"},"content":{"rendered":"<p>In my earlier discussion of the fact that <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/02\/27\/539880.aspx\"> changing a class property affects all windows of that class<\/a>, commenters <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/02\/27\/539880.aspx#544387\"> LittleHelper<\/a> and <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/02\/27\/539880.aspx#544987\"> Norman Diamond<\/a> wanted to know &#8220;Why is the cursor associated with class and not a window?&#8221;\n This is another one of those questions that start off with an invalid assumption. The cursor is not associated with a class. The cursor is not associated with a window. The cursor is associated with an <i>input state<\/i>. (Initially, each thread has its own input state, but functions like <code>Attach&shy;Thread&shy;Input<\/code> can cause threads to share their input states.)\n As we saw when we explored <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/11\/21\/1115695.aspx\"> the process by which the cursor gets set<\/a>, the cursor-setting process is initiated by the <code>WM_SETCURSOR<\/code> message, which is percolated up and down the window hierarchy until somebody calls <code>Set&shy;Cursor<\/code> and returns <code>TRUE<\/code> to say &#8220;Okay, I set the cursor. You can stop searching now.&#8221; And that cursor remains in effect until <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/05\/25\/421707.aspx\"> somebody else in the same thread group calls <code>Set&shy;Cursor<\/code><\/a>.\n It so happens that the <code>Def&shy;Window&shy;Proc<\/code> function, when asked to set a cursor, will use the window&#8217;s class cursor. But that&#8217;s just the default in the absence of any customization to the contrary. If you want to customize the cursor when it is over a particular window, then use the customization; don&#8217;t go changing the default. If you change the default, then you affect what happens to all the other windows of the class. Just handle the <code>WM_SETCURSOR<\/code> message to establish your &#8220;per-window cursor&#8221;. (And you can be even more specific than just per-window. For example, you might decide to show a hand cursor if the user is over a hyperlink but an arrow cursor otherwise.)<\/p>\n<p> Many of the fields in the <code>WND&shy;CLASS<\/code> structure are merely defaults which are applied to windows of the class. You can still override them on a per-window basis. <\/p>\n<table border=\"1\" style=\"border-collapse: collapse\" cellpadding=\"3\">\n<tbody>\n<tr>\n<th>Field<\/th>\n<th>How to override<\/th>\n<\/tr>\n<tr>\n<td><code>lpfn&shy;Wnd&shy;Proc<\/code><\/td>\n<td><code>Set&shy;Window&shy;Long&shy;Ptr(GWLP_WNDPROC)<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>hIcon<\/code><\/td>\n<td><code>Send&shy;Message(WM_SETICON)<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>hCursor<\/code><\/td>\n<td>Handle the <code>WM_SETCURSOR<\/code> message<\/td>\n<\/tr>\n<tr>\n<td><code>hbrBackground<\/code><\/td>\n<td>Handle the <code>WM_ERASEBKGND<\/code> message<\/td>\n<\/tr>\n<tr>\n<td><code>lpsz&shy;Menu&shy;Name<\/code><\/td>\n<td><code>Set&shy;Menu()<\/code><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p> (This is the same table I wrote up <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/06\/15\/632243.aspx\"> some time ago<\/a>, but the original table didn&#8217;t have an entry for the window procedure, so this table is <i>slightly<\/i> more complete. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my earlier discussion of the fact that changing a class property affects all windows of that class, commenters LittleHelper and Norman Diamond wanted to know &#8220;Why is the cursor associated with class and not a window?&#8221; This is another one of those questions that start off with an invalid assumption. The cursor is not [&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-11563","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>In my earlier discussion of the fact that changing a class property affects all windows of that class, commenters LittleHelper and Norman Diamond wanted to know &#8220;Why is the cursor associated with class and not a window?&#8221; This is another one of those questions that start off with an invalid assumption. The cursor is not [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11563","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=11563"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/11563\/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=11563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=11563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=11563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}