none
SubClassing CEdit in Visual C++ 6 RRS feed

  • Question

  • Hi

    I try subclassing CEdit in Visual C++ 6.

    I need it so I can

    1. better control input on-line per control and not leaving it to the DDX_DDV at end of the Dialog

    2. react in the View to certain keys pressed while the CEdit has the focus

    3. enable the resource editor and the Wizards recognize my CEdit

    I cannot find a complete example and I am now after too many hours experimenting the ( evidently ) wrong ways.

    Is there a simple complete example that works in Document-View in Visual C++ 6?

    Many thanks in advance

    Gad Tavor

     

     

     


    Friday, August 26, 2011 4:09 PM

Answers

  • You forgot to add #include "GTEdit.h" up near the top of gagaview.h

    By reading the #include file the compiler knows what CGTEdit is.  Without that you get the errors you posted.

     

    • Marked as answer by Rob Pan Thursday, September 1, 2011 9:05 AM
    Saturday, August 27, 2011 1:17 AM

All replies

  • Here is one example

    http://www.codeproject.com/Tips/83992/Subclassing-CEdit-to-disable-clipboard-operations.aspx

    If you search that site for CEdit + subclass you will find several more examples.

     

    Friday, August 26, 2011 5:25 PM
  • Thanks

    I have seen this example and others already. It did not help. I am already after many hours trying many ways with no success.

    I have a small project in Visual C++ 6,  a small SDI one. Simply to learn by it what I need. The View has 2 CEdit controlls and few Buttons and all works as expected until I try tame the CEdit.

    I tried creating CMyEdit in the Dialog of the View using the Class Wizard in the IDE of Visual C++ 6 SDI project with the Resource Editor creating Custom Controll with minimal functionality.

    1. Is it possible to subclass CEdit in the Document-View environment? How do I do it?

    2. Can I add myCEdit to the Resource Editor?

    Certainly I miss some details. this is why a complete example is helpfull so I can identify my errors.

    Thanks

    Gad Tavor

    Friday, August 26, 2011 6:14 PM
  • You need a class you derive from CEdit, like CMyEdit.

    Put an ordinary CEdit control on the dialog template.  (Not a custom control.)  Use class wizard to add a control member variable.  It will look like CEdit m_myedit in the view .h file.

    Edit your view .h file to #include "MyEdit.h" and change the CEdit m_myedit into CMyEdit m_myedit.

    That's all you need.

    You cannot add CMyEdit to the resource editor. As far as the resource editor is concerned you are using an ordinary CEdit.

     


    Friday, August 26, 2011 9:00 PM
  • Thanks for the prompt reply.
     
    I did what you suggested. It does not compile for some reason.
     
    Once I define in CView.h something like that :
     
    CGTEdit m_Num;  
    CGTEdit* pGTEd;
     
    or the like I get compile errors :
     
    43: syntax error : missing ';' before '*'
    d:\vcprojects\gaga\gagaview.h(32) : error C2501: 'CGTEdit' : missing storage-class or type specifiers
    d:\vcprojects\gaga\gagaview.h(32) : error C2501: 'pGTEd' : missing storage-class or type specifiers
    gagaView.cpp

     
    as if for some reason it refuses to recognize my class derived from CEdit in the CView. The GTEdit.h and .cpp compiled OK.
     
    I have already been there before and it is very frustrating.
     
    Hope you can help me somehow.
     
    Thanks in advance
     
    Gad Tavor
    Saturday, August 27, 2011 12:06 AM
  • You forgot to add #include "GTEdit.h" up near the top of gagaview.h

    By reading the #include file the compiler knows what CGTEdit is.  Without that you get the errors you posted.

     

    • Marked as answer by Rob Pan Thursday, September 1, 2011 9:05 AM
    Saturday, August 27, 2011 1:17 AM