Assign unique value for duplicated id, simply. You should assign all unique (different) id for different controls. Only one handler will be called for one id value on MFC message mapping. Because MFC's message mapping is very simple implement which using array of struct, and decide handler by sequential searching. When message map is as below;
BEGIN_MESSAGE_MAP(CSampleDlg, CDialog)
//{{AFX_MSG_MAP(CSampleDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Compiler recognize as below; (rewriting simply)
struct MessageEntry messageEntries[] = {
{ IDC_BUTTON1, OnButton1 },
{ IDC_BUTTON2, OnButton2 }
};
If IDC_BUTTON1 and IDC_BUTTON2 are equal, the sequential searching algorithm always find OnButton1 for IDC_BUTTON{1,2}.