{"content":"What sort of horrible things happen if my dialog has a non-button with the control ID of IDCANCEL?\n\nI noted in the bonus chatter that if you have a control whose ID is IDCANCEL, it had better be a button if you know what’s good for you. Shawn Keene doesn’t know what’s good for him and asks, “I can’t wait to find out what happens if my control is not a button.”\n\nWhat happens is that the dialog manager will generate a WM_COMMAND message as if your IDCANCEL control were a button, even if it isn’t.\n\nThis means that the message arrives with a notification code of BN_CLICKED, a control ID of IDCANCEL, and a window handle of your not-actually-a-button window.\n\nSince your control is not actually a button, it will treat the BN_CLICKED as if it were a notification appropriate to its type. The numeric value of BN_CLICKED is zero, so it’ll be treated as whatever a notification code of zero means for that control type. For example, if it’s actually a static control, you’ll interpret the zero to mean STN_CLICKED.\n\nIf it’s actually a list box, then you’ll see the zero and say “Huh? I don’t see any notification code with the numeric value of zero. What’s going on?”\n\nIf it’s a custom control, you will interpret the zero as whatever that custom control defines notification code zero to mean.\n\nBasically, what you did is signed yourself up for confusion. You’re going to get a WM_COMMAND message with BN_CLICKED as the notification code, IDCANCEL as the control ID, and your non-button window as the control. What you do with that information is up to you.\n\nBonus reading: Why do dialog editors start assigning control IDs with 100?\n\nThe post What sort of horrible things happen if my dialog has a non-button with the control ID of IDCANCEL? appeared first on The Old New Thing.","contentType":"text/plain;utf-8","attachments":[],"quotePin":""}