{"id":30863,"date":"2006-06-15T10:00:00","date_gmt":"2006-06-15T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2006\/06\/15\/window-class-properties-apply-to-all-windows-that-belong-to-the-class\/"},"modified":"2006-06-15T10:00:00","modified_gmt":"2006-06-15T10:00:00","slug":"window-class-properties-apply-to-all-windows-that-belong-to-the-class","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20060615-00\/?p=30863","title":{"rendered":"Window class properties apply to all windows that belong to the class"},"content":{"rendered":"<p>\nWindow class properties apply to all windows that belong to the class<\/a>.\nThat&#8217;s why they&#8217;re called class properties.\nThis seems like an obvious thing to say when put in so many words,\nbut I see many &#8220;solutions&#8221; that lose sight of this simple fact.\n<\/p>\n<p>\nAll the properties that you set in the <code>WNDCLASS<\/code>\n(or <code>WNDCLASSEX<\/code>)\nare window class properties,\nas are the properties that you can access via\n<code>Get\/SetClassWord\/Long\/LongPtr<\/code>.\nThis means that\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2006\/02\/27\/539880.aspx\">\nwhen you change those properties,\nthey affect the entire class<\/a>.\nFor example, if you write\n<\/p>\n<pre>\nSetClassLongPtr(hwnd, GCLP_HCURSOR, (LONG_PTR)hcurNew);\n<\/pre>\n<p>\nthen you aren&#8217;t just changing the cursor for the window\nspecified by <code>hwnd<\/code>.\nYou&#8217;re changing the cursor for all windows of the same class\nas <code>hwnd<\/code>.\nFor example, if <code>hwnd<\/code> is an edit control,\nthen you changed the default cursor for all edit controls.\n<\/p>\n<p>\nBut what if you want to change a class property for just one\nparticular window instead of for all windows of a class?\n<\/p>\n<p>\nIf you want to change the menu, background, cursor, or icon\nfor a particular window,\nyou can override the class default\non a per-window basis:\n<\/p>\n<table BORDER=\"1\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Property<\/th>\n<th>Method<\/th>\n<\/tr>\n<tr>\n<td VALIGN=\"BASELINE\">Menu<\/td>\n<td VALIGN=\"BASELINE\"><code>SetMenu(hwnd, hmenuNew)<\/code> +\n                        destroy the old menu<\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"BASELINE\">Background<\/td>\n<td VALIGN=\"BASELINE\">Override <code>WM_ERASEBKGND<\/code><\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"BASELINE\">Cursor<\/td>\n<td VALIGN=\"BASELINE\">Override <code>WM_SETCURSOR<\/code><\/td>\n<\/tr>\n<tr>\n<td VALIGN=\"BASELINE\">Icon<\/td>\n<td VALIGN=\"BASELINE\"><code>SendMessage(hwnd, WM_SETICON, iconSize, (LPARAM)hiconNew)<\/code><\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Window class properties apply to all windows that belong to the class. That&#8217;s why they&#8217;re called class properties. This seems like an obvious thing to say when put in so many words, but I see many &#8220;solutions&#8221; that lose sight of this simple fact. All the properties that you set in the WNDCLASS (or WNDCLASSEX) [&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-30863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Window class properties apply to all windows that belong to the class. That&#8217;s why they&#8217;re called class properties. This seems like an obvious thing to say when put in so many words, but I see many &#8220;solutions&#8221; that lose sight of this simple fact. All the properties that you set in the WNDCLASS (or WNDCLASSEX) [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/30863","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=30863"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/30863\/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=30863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=30863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=30863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}