{"id":44533,"date":"2015-03-05T07:00:00","date_gmt":"2015-03-05T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/03\/05\/modifying-the-cs_noclose-style-does-affect-all-windows-of-the-class-just-not-necessarily-in-an-immediately-noticeable-way\/"},"modified":"2019-03-13T12:13:32","modified_gmt":"2019-03-13T19:13:32","slug":"20150305-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150305-00\/?p=44533","title":{"rendered":"Modifying the CS_NOCLOSE style does affect all windows of the class, just not necessarily in an immediately noticeable way"},"content":{"rendered":"<p>In a discussion of  <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/06\/04\/10019758.aspx\">how not to disable the Close button<\/a>, Rick&nbsp;C claims that <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/06\/04\/10019758.aspx#10020169\">changing the style does not affect windows that are already created<\/a>. <\/p>\n<p>Actually, it does. You can&#8217;t see it, but the effect is there. <\/p>\n<p>Take our <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">scratch program<\/a> and make these changes: <\/p>\n<pre>\n<font COLOR=\"blue\">DWORD CALLBACK NewThread(void *)\n{\n  CreateWindow(\n      TEXT(\"Scratch\"),\n      TEXT(\"Scratch 2\"),\n      WS_VISIBLE | WS_OVERLAPPEDWINDOW,\n      CW_USEDEFAULT, CW_USEDEFAULT,\n      CW_USEDEFAULT, CW_USEDEFAULT,\n      NULL, NULL, g_hinst, 0);\n\n  MSG msg;\n  while (GetMessage(&amp;msg, NULL, 0, 0)) {\n    TranslateMessage(&amp;msg);\n    DispatchMessage(&amp;msg);\n  }\n\n  return 0;\n}\n\nvoid OnChar(HWND hwnd, TCHAR ch, int cRepeat)\n{\n  DWORD id;\n\n  switch (ch) {\n  case ' ':\n    SetClassLong(hwnd, GCL_STYLE,\n                 GetClassLong(hwnd, GCL_STYLE) ^ CS_NOCLOSE);\n    break;\n\n  case '+':\n    CloseHandle(CreateThread(0, 0, NewThread, 0, 0, &amp;id));\n    break;\n  }\n}\n\n  HANDLE_MSG(hwnd, WM_CHAR, OnChar);<\/font>\n<\/pre>\n<p>Run this program, hit the <kbd>+<\/kbd> to open another window, then hit the space bar to set the <code>CS_NOCLOSE<\/code> style. <\/p>\n<p>The window that is passed to <code>Set&shy;Class&shy;Long<\/code> updates its close button, but the other window does not. <\/p>\n<p>But this is purely a visual artifact. If you try to click on the close button of either window, it will not work. <\/p>\n<p>So don&#8217;t change the <code>CS_NO&shy;CLOSE<\/code> style thinking that it affects just your window. It actually affects all windows of the class. But it may not look that way at a casual glance. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s there, you just can&#8217;t see it.<\/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-44533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>It&#8217;s there, you just can&#8217;t see it.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44533","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=44533"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44533\/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=44533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=44533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=44533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}