{"id":22663,"date":"2008-04-21T10:00:00","date_gmt":"2008-04-21T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/04\/21\/windows-doesnt-close-windows-when-a-user-logs-off-thats-your-call\/"},"modified":"2008-04-21T10:00:00","modified_gmt":"2008-04-21T10:00:00","slug":"windows-doesnt-close-windows-when-a-user-logs-off-thats-your-call","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080421-00\/?p=22663","title":{"rendered":"Windows doesn&#039;t close windows when a user logs off; that&#039;s your call"},"content":{"rendered":"<p>Commenter Peter Kankowski asks <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#511930\"> why Windows doesn&#8217;t send <code>WM_CLOSE<\/code> and <code>WM_DESTROY<\/code> messages when the user logs off<\/a>.\n That&#8217;s what <code>WM_ENDSESSION<\/code> is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end.\n Windows doesn&#8217;t send the <code>WM_CLOSE<\/code> message because sending <code>WM_CLOSE<\/code> becomes complicated once there is more than one window. What is the correct order for sending <code>WM_CLOSE<\/code> when there are multiple windows? Besides, many programs don&#8217;t respond to <code>WM_CLOSE<\/code> by closing. Instant messenger programs typically treat <code>WM_CLOSE<\/code> to mean &#8220;hide&#8221; rather than &#8220;close&#8221;. Notepad displays an unsaved data warning when you close the window. And of course, you can&#8217;t close a disabled window.\n As we saw with Notepad, sending a <code>WM_CLOSE<\/code> would just repeat actions that were taken during <code>WM_ENDSESSION<\/code>, which is particularly bad because the time for user interaction is over. <code>WM_QUERYENDSESSION<\/code> is the time to say your last good-byes. If Windows sent the <code>WM_CLOSE<\/code> message during logoff, Notepad would display a &#8220;You have unsaved changes. Do you want to save this file?&#8221; message after the user already said, &#8220;Go ahead and exit without saving,&#8221; when Notepad handled the <code>WM_QUERYENDSESSION<\/code> message. &#8220;Stupid computer. Why is it asking me this question again?&#8221; Even worse, what if the user says &#8220;Cancel&#8221;? It&#8217;s too late; shutdown has begun. Your chance to cancel it was back when you got the <code>WM_QUERYENDSESSION<\/code> message.\n Asking for the <code>WM_DESTROY<\/code> message is even weirder, since that message is not sent explicitly but is rather generated when <code>DestroyWindow<\/code> is called. You can&#8217;t just send it outside of a destroy sequence.\n Besides, why spend your time closing windows when the session is about to go away anyway? Ooh, let me clean up this and destroy that, I know you asked to shut down, but this&#8217;ll just take a few seconds. It&#8217;s like taking the time to steam-clean the rugs before you demolish the building. Wasted effort.<\/p>\n<p> Now, you might respond, &#8220;Yeah, sure, these are problems, but we should just require programs to address them, such as not putting up additional UI if they get a <code>WM_CLOSE<\/code> after a <code>WM_ENDSESSION<\/code>.&#8221; Of course, this argument contradicts the rationale for the original question, since the question was inspired by programs that didn&#8217;t handle the <code>WM_ENDSESSION<\/code> correctly in the first place! &#8220;We have a problem with programs that don&#8217;t handle the <code>WM_ENDSESSION<\/code> message correctly. Solution: Make <code>WM_ENDSESSION<\/code> more complicated.&#8221; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Peter Kankowski asks why Windows doesn&#8217;t send WM_CLOSE and WM_DESTROY messages when the user logs off. That&#8217;s what WM_ENDSESSION is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end. Windows doesn&#8217;t [&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-22663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter Peter Kankowski asks why Windows doesn&#8217;t send WM_CLOSE and WM_DESTROY messages when the user logs off. That&#8217;s what WM_ENDSESSION is for. To tell the program that the Windows session is ending, and that you should get done whatever last things you want to get done before the world comes to an end. Windows doesn&#8217;t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22663","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=22663"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/22663\/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=22663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=22663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=22663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}