CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    May 2013

    Subclassing CRichEditCtrl VS2008 Windows 7

    QUESTION: What is the class name of CRichEditCtrl? More generally, how can I figure this out myself eg with the debugger or documentation?


    I've successfully made 3-4 fairly complicated controls from scratch, starting by subclassing CButton as shown in some of the associated example projects.

    My current project needs a CRichEditCtrl, with just a slight bit of extra functionality.

    I've always used a method called RegisterControlClass(), taken from the example projects, that filled in a WNDCLASS structure by getting another class's WNDCLASS then just modifying it a bit. To get the initial values I used the class name "button" as that was in the example program. It worked fine.

    Now, to get the name of SCRichEdit, I'm stumped.

    I started by examining a real CRichEditCtrl:

    CRichEditCtrl* prich = (CRichEditCtrl*) GetDlgItem( IDC_PATCH );

    I've tried using the debugger and looking at prich->GetRuntimeClass()->m_lpszClassName, but it equals "CWnd". Obviously wrong.

    I found some docs on the 'net referring to MSFTEDIT_CLASS, which has a value of "RICHEDIT50W", that doesn't seem to work either.

    I found some fields deep inside the prich object in the debugger leading me to think it might be simply "CRichEditCtrl" but alas not that either.

    Here's the function with the class name "button" that works albeit isn't what I want.

    BOOL SCRichEdit::RegisterControlClass() {
      // STEP 1: check to see if a class is already registered with this name.
      // If it is, and the WndProcHook is ours, then WE'VE already registered
      // and its OK.  Otherwise someone else is using the same class name.  Not OK.
      WNDCLASS           wclsSCRichEdit;
      static const TCHAR szClass[] = _T( "SCRichEdit" );
      if ( ::GetClassInfo( AfxGetInstanceHandle(), szClass, &wclsSCRichEdit ) )
          return wclsSCRichEdit.lpfnWndProc == (WNDPROC) SCRichEdit::WndProcHook;
      // STEP 2: No "SCRichEdit" is registered, so register ourselves.  To do this,
      // we call RegisterClass() after filling out a WNDCLASS structure.  Rather
      // than fill it all out ourselves, we'll just duplicate the one used by
      // the built-in "button" class and change a couple fields.
      VERIFY( ::GetClassInfo( NULL, _T( "button" ), &wclsSCRichEdit ) );
      wclsSCRichEdit.lpfnWndProc   = SCRichEdit::WndProcHook;
      wclsSCRichEdit.hInstance     = AfxGetInstanceHandle();
      wclsSCRichEdit.lpszClassName = szClass;
      return RegisterClass( &wclsSCRichEdit ) != 0;
    Last edited by Swiss Frank; September 10th, 2013 at 02:27 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.