{"id":13403,"date":"2010-07-19T07:00:00","date_gmt":"2010-07-19T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/07\/19\/to-enable-and-disable-a-window-use-the-enablewindow-function\/"},"modified":"2010-07-19T07:00:00","modified_gmt":"2010-07-19T07:00:00","slug":"to-enable-and-disable-a-window-use-the-enablewindow-function","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100719-00\/?p=13403","title":{"rendered":"To enable and disable a window, use the EnableWindow function"},"content":{"rendered":"<p>Commenter <a href=\"http:\/\/xenon.arcticus.com\"> Chris &#8216;Xenon&#8217; Hanson<\/a> points out that <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#1612950\"> fiddling with the <code>WS_DISABLED<\/code> style directly via <code>Set&shy;Window&shy;Long<\/code> leads to strange behavior<\/a>. However it isn&#8217;t the case that &#8220;most widget classes work fine.&#8221; Reaching in and fiddling the style bit directly is like reaching into a program&#8217;s internal variables and just changing the values: All the other work that is associated with changing the value simply doesn&#8217;t happen.\n It&#8217;s like taking a book you checked out of the library, re-shelving it, and then going into the library computer and marking it as &#8220;returned&#8221;. The bookkeeping will say that the book has been returned, but all the other processes associated with a book return has not taken place: People who had placed a hold on the book aren&#8217;t notified. The &#8220;number of books checked out&#8221; counter isn&#8217;t updated. (Which gets interesting when you come to the end of your senior year and the system won&#8217;t let you graduate because its records say that you still have 1 book outstanding, yet when you say &#8220;Show me all the books I have checked out&#8221; it returns no records.)\n In the case of windows, merely setting the <code>WS_DISABLED<\/code> style does not generate <code>WM_ENABLE<\/code> messages, it doesn&#8217;t generate accessibility notifications, it doesn&#8217;t do focus bookkeeping, all it does is set the flag and goes home. Eventually, some code will stop working because something &#8220;impossible&#8221; happened (in this case, a window transitioning from enabled to disabled without ever receiving a <code>WM_ENABLE<\/code> message).\n Similarly, the way to change a window&#8217;s visible state is to use the <code>Show&shy;Window<\/code> function and not to manipulate the <code>WS_VISIBLE<\/code> style directly.\n &#8220;I think I filed a suggestion on MSDN2.microsoft.com&#8217;s suggestion box to advise people not to fiddle with the <code>WS_DISABLED<\/code> flag at runtime via <code>Set&shy;Window&shy;Long()<\/code> since it seems like a viable route if you don&#8217;t know otherwise.&#8221;<\/p>\n<p> Actually, the advice already exists right at the top of the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms632600.aspx\"> Window Styles<\/a> page where it  says &#8220;After the control has been created, these styles cannot be modified, except as noted.&#8221; And for <code>WS_DISABLED<\/code>, it says &#8220;To change this after a window has been created, use <code>Enable&shy;Window<\/code>.&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Chris &#8216;Xenon&#8217; Hanson points out that fiddling with the WS_DISABLED style directly via Set&shy;Window&shy;Long leads to strange behavior. However it isn&#8217;t the case that &#8220;most widget classes work fine.&#8221; Reaching in and fiddling the style bit directly is like reaching into a program&#8217;s internal variables and just changing the values: All the other work [&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-13403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter Chris &#8216;Xenon&#8217; Hanson points out that fiddling with the WS_DISABLED style directly via Set&shy;Window&shy;Long leads to strange behavior. However it isn&#8217;t the case that &#8220;most widget classes work fine.&#8221; Reaching in and fiddling the style bit directly is like reaching into a program&#8217;s internal variables and just changing the values: All the other work [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13403","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=13403"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/13403\/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=13403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=13403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=13403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}