A: 

CWnd::Create is a virtual function. If you override it and call your base class's (CRichEditCtrl's) Create first, you can then assume the Window handle is available.

Something like this:

   BOOL MyEditControl::Create(
     LPCTSTR lpszClassName,
     LPCTSTR lpszWindowName,
     DWORD dwStyle,
     Const RECT& rect,
     CWnd* pParentWnd,
     UINT nID,
     CCreateContext* pContext)
   {
    CRichEditControl::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
    // call functions that use the window handle

   }
David Gladfelter
Tried that, see my edit. Doesn't work. But in my .rc file I have a standard **CRichEditCtrl**, bound to a **MyEditCtrl** using DDX. I guess that only works on methods declared virtual in **CRichEditCtrl**. What else do I need to add?
John
I'm a little confused. If Create/CreateEx is never called, how could MyEditCtrl ever have a window handle?
David Gladfelter
A: 

From your response to the earlier answer, it sounds a lot like you've got a CRichEditCtrl in a dialog. In MFC the dialog case is different from creating controls manually: the dialog controls (that is, the Windows controls, not the MFC objects) are created by the dialog manager, which are then coupled to the MFC objects by bits of the MFC infrastructure.

As you've found, in this case the MFC Create() or CreateEx() function is never called. Instead, the dialog manager creates the control, and it's attached to the MFC object by a call to SubclassDlgItem(). If you override that function, you'll find that it's called during dialog creation.

However, an easier way to deal with what you want is to put the call to SetEventMask() in the dialog's OnInitDialog() handler. This handler runs in response to the WM_INITDIALOG message, which is sent just after all the Windows controls are created and tied to the MFC objects.

DavidK
This actually didn't work either. I updated my question with the solution I used.
John
OnInitDialog is the standard way to do this - it's what everyone does. Not sure why it didn't work for you, but it's worth trying to figure out why it didn't.
DavidK