CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 1999
    Posts
    11

    Deriving intermediary class from CFormView

    I have a project which has several FormViews attached to the same document. They all do different things, but share some functionality. I would like to do what I think is the correct OO thing - stuff the shared code into an intermediary class derived from CFormView, and then derive my real FormViews from this class. I tried this by deriving a CBaseView from CFormView using class wizard (using a sparse dialog as a dummy placeholder), and then doing a global replace of CFormView with this derived class in one of my "real" FormViews, but the compiler chokes saying the CBaseView constructor doesn't take 1 parameter. I did a few experiments, but basically, I got into a terrible tangle with the various macros concerning the template, dynamic creation etc. I think the problem lies in passing the real dialog template back to CFormView, but I am not sure. Can anyone tell me a) is it possible to do what I want, and if so, b) what's the syntax?



  2. #2
    Join Date
    Jul 1999
    Location
    Germany, Dresden
    Posts
    71

    Re: Deriving intermediary class from CFormView

    I use following implementation:

    class CmyFormView : public CFormView
    {
    protected: // create from serialization only
    CsdeFormView();
    CsdeFormView( UINT nIDTemplate );
    DECLARE_DYNCREATE(CsdeFormView)
    ...
    }; // class CmyFormView

    IMPLEMENT_DYNCREATE(CmyFormView, CFormView)

    CmyFormView::CmyFormView()
    : CFormView(UINT_MAX)
    {
    // ... should be never called
    } // construction

    CmyFormView::CmyFormView( UINT nIDTemplate )
    : CFormView(nIDTemplate)
    {
    // ... do something
    } // construction



  3. #3
    Join Date
    Sep 1999
    Posts
    11

    Re: Deriving intermediary class from CFormView

    I'm a bit puzzled by your message on 2 points:

    First, in
    class CmyFormView : public CFormView
    {
    protected: // create from serialization only
    CsdeFormView();

    is the "CsdeFormView" a typo for CmyFormView, or am I missing something crucial?

    Second, if I understand it correctly, I think you are deriving directly from CFormView. I have several FormView-derived classes,
    and what I want is to make an intermediary class into which I can put some code which is common to all of them
    CFormView // provides basic FormView functionality
    CIntermediaryFormView // provides some common code (for printing, actually)
    CRealFormView1, CRealFormView2, CRealFormView3 // displays on screen as FormView, with access to comon printing code

    Best wishes

    Bill



  4. #4
    Join Date
    Jul 1999
    Location
    Germany, Dresden
    Posts
    71

    Re: Deriving intermediary class from CFormView

    At first, sorry Bill, "CsdeFormView" should be "CmyFormView", it's a typo.

    At second you are right, use the Wizard if you want and change later "CFormView" to "CmyFormView" in the *.h and *.cpp Files

    class CRealFormView1 : public CmyFormView
    {
    protected:
    CRealFormView1(); // protected constructor used by dynamic creation
    DECLARE_DYNCREATE(CRealFormView1)

    // Form Data
    public:
    ~CRealFormView1(); // destructor

    //{{AFX_DATA(CRealFormView1)
    enum { IDD = IDD_REAL1_FORM };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // .... and so on

    Hope that help you

    Axel


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured