title: Can't create several windows of the same class, why?
body: <p>I am pretty new to MFC so this question is probably very dumb, but I can't seem to find the answer on my own, so here goes.</p>
  
  <p>I have a custom window control derived from CWnd. When I use just one instance of that control in my dialog, everything is fine. Now I tried to create several instances like this:</p>
  
  <pre><code>for (int i = 0; i &lt; 10; i++)
  {
      control[i] = new CMyControl;
      control[i]-&gt;CreateEx(exStyle, name, "", style, CRect(i * 10, 0, 10, 10), 
                           this, IDC_FIRST + i, 0);
  }
  </code></pre>
  
  <p>Creation goes fine, CreateEx() returns TRUE, but as far as message handling goes, only the very first instance receives anything, the rest receive WM_CREATE and then silence, not a single WM_PAINT.</p>
  
  <p>What am I doing wrong here?</p>
  
  <p>Edit: the whole thing looks like this:</p>
  
  <pre><code>class CMyControl : public CWnd
  {
  public: 
      CMyControl()
      {
          m_ClassName = AfxRegisterWndClass(
                      CS_VREDRAW | CS_HREDRAW,
                      ::LoadCursor(NULL, IDC_ARROW),
                      (HBRUSH) ::GetStockObject(WHITE_BRUSH),
                      ::LoadIcon(NULL, IDI_APPLICATION));
      } 
  
      LPCTSTR GetClassName() const {return m_ClassName;}
  
  protected:    
  
      afx_msg int OnCreate(LPCREATESTRUCT) {return 0;}
      afx_msg void OnPaint() {}
  
  DECLARE_MESSAGE_MAP()
  
  private:   
      LPCTSTR m_ClassName;
  };
  
  BEGIN_MESSAGE_MAP(CMyControl, CWnd)
      ON_WM_CREATE()
      ON_WM_PAINT()    
  END_MESSAGE_MAP()
  
  //then, in my main dialog's OnInitDialog,
  
  BOOL CMyDialog::OnInitDialog()
  {
      CDialogEx::OnInitDialog();
  
      CMyControl* controls[10];
  
      for (unsigned int i = 0; i &lt; 10; i++)
      {
          controls[i] = new CMyControl;
          controls[i]-&gt;CreateEx(WS_EX_CLIENTEDGE, controls[i]-&gt;GetClassName(), L"", 
          WS_CHILD | WS_VISIBLE, CRect(i*10, 0, 10, 10), this, 1006 + i, 0);
      }
      return TRUE;
  }
  </code></pre>
  
  <p>No deallocation code here, the principle is the same though.</p>
  
  <p>Edit 2: Ok, figured it out. The reason is that I'm an imbecile:</p>
  
  <pre><code>CRect(i * 10, 0, 10, 10)
  </code></pre>
  
  <p>arguments are left/right/top/bottom and not left/right/width/height.</p>
  
  <p>Sorry about that.</p>