title: How to handle messages from dynamically created controls in an MFC app?
body: <p>Imagine I have a CDialog which creates controls dynamically when the user clicks a button. It could be like this:</p>
  
  <pre><code>// We don't know which is the first id for the new buttons until runtime (!)
  MyDialog::MyDialog(/*whatever parameters needed*/, first_id)
    : next_id_(first_id) 
  { /*...*/ }
  
  BOOL MyDialog::OnSomeButtonClicked()
  {
    CButton* new_button = new CButton;
    new_button-&gt;Create("Caption", WS_CHILD | WS_VISIBLE, this-&gt;new_button_rect_, 
                       this, this-&gt;next_id_++);
  }
  </code></pre>
  
  <p>Then my question would be: How could I handle messages from this button? Is it possible to use the MFC message map facility?</p>
  
  <p>The solution should work in both vs6 and vs2005.</p>
  
  <p>Thank you!</p>