{"id":112098,"date":"2026-03-02T12:55:53","date_gmt":"2026-03-02T20:55:53","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112098"},"modified":"2026-03-02T12:55:53","modified_gmt":"2026-03-02T20:55:53","slug":"20260302-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260302-53\/?p=112098","title":{"rendered":"What sort of horrible things happen if my dialog has a non-button with the control ID of <CODE>IDCANCEL<\/CODE>?"},"content":{"rendered":"<p>I noted in the bonus chatter that <a title=\"Exploring the signals the dialog manager uses for dismissing a dialog\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260219-00\/?p=112072\"> 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<\/a>. Shawn Keene doesn&#8217;t know what&#8217;s good for him and asks, &#8220;<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260219-00\/?p=112072&amp;commentid=143844#comment-143844\">I can&#8217;t wait to find out what happens if my control is not a button<\/a>.&#8221;<\/p>\n<p>What happens is that the dialog manager will generate a <code>WM_<wbr \/>COMMAND<\/code> message <i>as if<\/i> your <code>IDCANCEL<\/code> control were a button, even if it isn&#8217;t.<\/p>\n<p>This means that the message arrives with a notification code of <code>BN_<wbr \/>CLICKED<\/code>, a control ID of <code>IDCANCEL<\/code>, and a window handle of your not-actually-a-button window.<\/p>\n<p>Since your control is not actually a button, it will treat the <code>BN_<wbr \/>CLICKED<\/code> as if it were a notification appropriate to its type. The numeric value of <code>BN_<wbr \/>CLICKED<\/code> is zero, so it&#8217;ll be treated as whatever a notification code of zero means for that control type. For example, if it&#8217;s actually a static control, you&#8217;ll interpret the zero to mean <code>STN_<wbr \/>CLICKED<\/code>.<\/p>\n<p>If it&#8217;s actually a list box, then you&#8217;ll see the zero and say &#8220;Huh? I don&#8217;t see any notification code with the numeric value of zero. What&#8217;s going on?&#8221;<\/p>\n<p>If it&#8217;s a custom control, you will interpret the zero as whatever that custom control defines notification code zero to mean.<\/p>\n<p>Basically, what you did is signed yourself up for confusion. You&#8217;re going to get a WM_<wbr \/>COMMAND message with <code>BN_<wbr \/>CLICKED<\/code> as the notification code, <code>IDCANCEL<\/code> as the control ID, and your non-button window as the control. What you do with that information is up to you.<\/p>\n<p><b>Bonus reading<\/b>: <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20041214-00\/?p=37013\"> Why do dialog editors start assigning control IDs with 100<\/a>?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You get notifications that might not make sense.<\/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-112098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You get notifications that might not make sense.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112098","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=112098"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112098\/revisions"}],"predecessor-version":[{"id":112100,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112098\/revisions\/112100"}],"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=112098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}