title: How to define IDs for ON_CONTROL_RANGE c++ MFC WINAPI
body: <p>I'm comparatively new to MFC / C++ / WINAPI programming and currently I'm working on a project where I have to manage clicks of dynamically created Buttons.</p>
  
  <p>I did quite a lot of research and found the following approach with ON_CONTROL_RANGE:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/84xtde24.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/84xtde24.aspx</a></p>
  
  <p>I even made it working but my solution is not yet satisfying considering to write nice and clean code.</p>
  
  <p>My working solution:</p>
  
  <pre><code>BEGIN_MESSAGE_MAP(CFooter, CWnd)
      ON_WM_PAINT()
      ON_WM_LBUTTONDOWN()
      ON_WM_CREATE()
      ON_WM_SIZE()
      ON_CONTROL_RANGE(BN_CLICKED, 2000, 2030, OnButtonClicked)
  END_MESSAGE_MAP()
  </code></pre>
  
  <p>Handler Function in Class CFooter declared as:</p>
  
  <pre><code>afx_msg void OnButtonClicked(UINT nIDbutton){...}
  </code></pre>
  
  <p>With what I'm not happy yet is that my ID's are defined as raw integer numbers therefore I wanted to define values for them like:</p>
  
  <pre><code>#define IDC_FOOTER_FIRST_BUTTON_ID  2000;
  #define IDC_FOOTER_LAST_BUTTON_ID  2030;
  
  BEGIN_MESSAGE_MAP(CFooter, CWnd)
     ON_WM_PAINT()
     ON_WM_LBUTTONDOWN()
     ON_WM_CREATE()
     ON_WM_SIZE()
     ON_CONTROL_RANGE(BN_CLICKED, IDC_FOOTER_FIRST_BUTTON_ID, IDC_FOOTER_LAST_BUTTON_ID, OnButtonClicked)
  END_MESSAGE_MAP()
  </code></pre>
  
  <p>But this will not compile anymore.. Why is that what am I missing out?
  I tried to define the values in the header file outside of the class definition of CFooter and in the cpp file above the messagemap as shown.</p>
  
  <p>The errors are kind of cryptic e.g.:</p>
  
  <p>syntax error in line ON_CONTROL_RANGE ","<br>
  syntax error in line ON_CONTROL_RANGE "}"<br>
  _messageEntries: undeclared identifier<br>
  GetThisMessageMap: undeclared identifier</p>
  
  <p>So I assume I'm not defining my IDs correctly / at the right spot.. 
  Can someone give me an Explanation what I'm doing wrong and where / how to define the ID's correctly? </p>
  
  <p>Thanks in advance</p>