{"id":112072,"date":"2026-02-19T07:00:00","date_gmt":"2026-02-19T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112072"},"modified":"2026-02-19T08:09:26","modified_gmt":"2026-02-19T16:09:26","slug":"20260219-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260219-00\/?p=112072","title":{"rendered":"Exploring the signals the dialog manager uses for dismissing a dialog"},"content":{"rendered":"<p>There are a few different built-in ways to close a dialog box in the classic Windows dialog manager. Let&#8217;s run them down.<\/p>\n<p>First, there&#8217;s hitting the <kbd>ESC<\/kbd> key.<\/p>\n<p>The <kbd>ESC<\/kbd> key, as with all keyboard navigation, is handled by the <code>Is\u00adDialog\u00adMessage<\/code> function. Assuming that the dialog control with focus did not use the <code>WM_<wbr \/>GET\u00adDLG\u00adCODE<\/code> message to override default keyboard handling, the <code>Is\u00adDialog\u00adMessage<\/code> function converts the <kbd>ESC<\/kbd> to a simulated button click of whatever dialog control has the ID <code>IDCANCEL<\/code>. Specifically, the message is <code>WM_<wbr \/>COMMAND<\/code>, the notification code is <code>BN_<wbr \/>CLICKED<\/code>, the control ID is <code>IDCANCEL<\/code>, and the window handle is the handle to whatever dialog control has the ID <code>IDCANCEL<\/code> (or <code>nullptr<\/code> if there is no such control).<\/p>\n<p><b>Exception<\/b>: If there is a control whose ID is <code>IDCANCEL<\/code>, and that control is disabled, then the <code>Is\u00adDialog\u00adMessage<\/code> function merely beeps and otherwise ignores the <kbd>ESC<\/kbd> key.<\/p>\n<p>Okay, what about the Close button in the title bar, the one that looks like an \u00d7?<\/p>\n<p>The Close button in the title bar, double-clicking the dialog box icon (if there is one), selecting Close from the system menu, and pressing <kbd>Alt<\/kbd>+<kbd>F4<\/kbd> all behave the same way: They generate a <code>WM_<wbr \/>SYSCOMMAND<\/code> message whose <code>wParam &amp; 0xFFF0<\/code> is <code>SC_<wbr \/>CLOSE<\/code>. The default window procedure turns this into a <code>WM_CLOSE<\/code> message. The default dialog procedure responds to the <code>WM_CLOSE<\/code> in basically the same way that <code>Is\u00adDialog\u00adMessage<\/code> does: It generates a simulated button click of whatever dialog control has the ID <code>IDCANCEL<\/code>. Again, this is done by converting it to the <code>WM_<wbr \/>COMMAND<\/code> message, with a notification code of <code>BN_<wbr \/>CLICKED<\/code>, a control ID of <code>IDCANCEL<\/code>, and the handle to whatever dialog control has the ID <code>IDCANCEL<\/code> (or <code>nullptr<\/code> if there is no such control). It also has the same exception: If there is a control whose ID is <code>IDCANCEL<\/code>, and that control is disabled, then the default dialog procedure just beeps and otherwise ignores the message.<\/p>\n<p>Now that we understand what happens, next time we can look at ways of customizing the behavior.<\/p>\n<p><b>Bonus chatter<\/b>: You can see from this that the dialog manager is wired to treat a control with the ID <code>IDCANCEL<\/code> as if it were a Cancel button, so <a title=\"Gentle reminder: On a dialog box, do not give OK and Cancel accelerators\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080508-00\/?p=22403\"> if you have a Cancel button, give it the ID <code>IDCANCEL<\/code><\/a>. Conversely, if you have a control whose ID is <code>IDCANCEL<\/code>, it had better be a button if you know what&#8217;s good for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summarizing the flow.<\/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-112072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Summarizing the flow.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112072","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=112072"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112072\/revisions"}],"predecessor-version":[{"id":112073,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112072\/revisions\/112073"}],"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=112072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}