Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can I properly derive from CMFCPropertyGridColorProperty ?

Can I properly derive from CMFCPropertyGridColorProperty ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
6 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    I'm trying to derive from CMFCPropertyGridColorProperty and cannot override the virtual function because my derived class is not a friend of CMFCPropertyGridCtrl. Here is a minimal representation of the problem.

    class CMFCPropertyGridCtrl
    {
    friend class CMFCPropertyGridColorProperty;

    protected:
    CRect m_rectList; // Properies area
    };

    class CMFCPropertyGridColorProperty
    {
    friend class CMFCPropertyGridCtrl;

    public:
    virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);

    protected:
    // back pointer
    CMFCPropertyGridCtrl* m_pWndList;
    };

    void CMFCPropertyGridColorProperty::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
    {
    // original code removed for clarity.

    // access to CMFCPropertyGridCtrl::m\_rectList;
    m\_pWndList->m\_rectList.left += 20;
    

    }

    class MyPropertyGrid : public CMFCPropertyGridColorProperty
    {
    virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);
    };

    void MyPropertyGrid::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
    {
    // original code removed for clarity.
    // access to CMFCPropertyGridCtrl::m_rectList;
    m_pWndList->m_rectList.left += 40; // ERROR.
    }

    trying to compile this, I get the following understandable error : error C2248: 'CMFCPropertyGridCtrl::m_rectList' : cannot access protected member declared in class 'CMFCPropertyGridCtrl' 1> d:\projects\testfriend\testfriend\testfriend.cpp(21) : see declaration of 'CMFCPropertyGridCtrl::m_rectList' 1> d:\projects\testfriend\testfriend\testfriend.cpp(17) : see declaration of 'CMFCPropertyGridCtrl' --- I'd like to be able to override the method

    virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);

    void CMFCPropertyGridColorProperty::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
    {
    ASSERT_VALID(this);
    ASSERT_VALID(m_pWndList);

    rectSpin.SetRectEmpty();
    
    rectEdit = m\_Rect;
    rectEdit.DeflateRect(0, 2);
    
    int nMargin = m\_pWndList->m\_bMarkModifiedProperties && m\_bIsModified ? m\_pWndList->m\_nBoldEditLeftMargin : m\_pWndList->m\_nEditLeftMargin;
    
    rectEdit.left = m\_pWndList->m\_rectList.left + m\_pWndList->m\_nLeftColumnWidth + m\_Rect.Height() + AFX\_TEXT\_MARGIN - nMargin + 1;
    
    AdjustButtonRect();
    rectEdit.right = m\_rectButton.left;
    

    }

    To change the edit box position in the CMFCPropertyGridColorProperty class; but since I do not have access to the CMFCPropertyGridCtrl class (via m_pWndList), I cannot really ove

    CPalliniC 1 Reply Last reply
    0
    • M Maximilien

      I'm trying to derive from CMFCPropertyGridColorProperty and cannot override the virtual function because my derived class is not a friend of CMFCPropertyGridCtrl. Here is a minimal representation of the problem.

      class CMFCPropertyGridCtrl
      {
      friend class CMFCPropertyGridColorProperty;

      protected:
      CRect m_rectList; // Properies area
      };

      class CMFCPropertyGridColorProperty
      {
      friend class CMFCPropertyGridCtrl;

      public:
      virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);

      protected:
      // back pointer
      CMFCPropertyGridCtrl* m_pWndList;
      };

      void CMFCPropertyGridColorProperty::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
      {
      // original code removed for clarity.

      // access to CMFCPropertyGridCtrl::m\_rectList;
      m\_pWndList->m\_rectList.left += 20;
      

      }

      class MyPropertyGrid : public CMFCPropertyGridColorProperty
      {
      virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);
      };

      void MyPropertyGrid::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
      {
      // original code removed for clarity.
      // access to CMFCPropertyGridCtrl::m_rectList;
      m_pWndList->m_rectList.left += 40; // ERROR.
      }

      trying to compile this, I get the following understandable error : error C2248: 'CMFCPropertyGridCtrl::m_rectList' : cannot access protected member declared in class 'CMFCPropertyGridCtrl' 1> d:\projects\testfriend\testfriend\testfriend.cpp(21) : see declaration of 'CMFCPropertyGridCtrl::m_rectList' 1> d:\projects\testfriend\testfriend\testfriend.cpp(17) : see declaration of 'CMFCPropertyGridCtrl' --- I'd like to be able to override the method

      virtual void AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin);

      void CMFCPropertyGridColorProperty::AdjustInPlaceEditRect(CRect& rectEdit, CRect& rectSpin)
      {
      ASSERT_VALID(this);
      ASSERT_VALID(m_pWndList);

      rectSpin.SetRectEmpty();
      
      rectEdit = m\_Rect;
      rectEdit.DeflateRect(0, 2);
      
      int nMargin = m\_pWndList->m\_bMarkModifiedProperties && m\_bIsModified ? m\_pWndList->m\_nBoldEditLeftMargin : m\_pWndList->m\_nEditLeftMargin;
      
      rectEdit.left = m\_pWndList->m\_rectList.left + m\_pWndList->m\_nLeftColumnWidth + m\_Rect.Height() + AFX\_TEXT\_MARGIN - nMargin + 1;
      
      AdjustButtonRect();
      rectEdit.right = m\_rectButton.left;
      

      }

      To change the edit box position in the CMFCPropertyGridColorProperty class; but since I do not have access to the CMFCPropertyGridCtrl class (via m_pWndList), I cannot really ove

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Why don't you inherit from both classes?

      Veni, vidi, vici.

      In testa che avete, signor di Ceprano?

      M 1 Reply Last reply
      0
      • CPalliniC CPallini

        Why don't you inherit from both classes?

        Veni, vidi, vici.

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #3

        YUCK!!! A colleague offered the same suggestion. I tried and it works... but I do not really like it.

        I'd rather be phishing!

        CPalliniC 1 Reply Last reply
        0
        • M Maximilien

          YUCK!!! A colleague offered the same suggestion. I tried and it works... but I do not really like it.

          I'd rather be phishing!

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Maximilien wrote:

          I tried and it works... but I do not really like it.

          You will love multiple inheritance. :-D

          Veni, vidi, vici.

          In testa che avete, signor di Ceprano?

          M 1 Reply Last reply
          0
          • CPalliniC CPallini

            Maximilien wrote:

            I tried and it works... but I do not really like it.

            You will love multiple inheritance. :-D

            Veni, vidi, vici.

            M Offline
            M Offline
            Maximilien
            wrote on last edited by
            #5

            Yeah, but ultimately it does not work. I cannot inherit from both CMFCPropertyGridColorProperty and CMFCPropertyGridCtrl. The CMFCPropertyGridCtrl is a UI container class containing instances of CMFCPropertyGridProperty. the CMFCPropertyGridCtrl is constructed before the CMFCPropertyGridProperty are constructed; and if I multiple inherit from CMFCPropertyGridCtrl , there will be 2 "instances" of the class and there should be only one. I'm still working on something.

            I'd rather be phishing!

            CPalliniC 1 Reply Last reply
            0
            • M Maximilien

              Yeah, but ultimately it does not work. I cannot inherit from both CMFCPropertyGridColorProperty and CMFCPropertyGridCtrl. The CMFCPropertyGridCtrl is a UI container class containing instances of CMFCPropertyGridProperty. the CMFCPropertyGridCtrl is constructed before the CMFCPropertyGridProperty are constructed; and if I multiple inherit from CMFCPropertyGridCtrl , there will be 2 "instances" of the class and there should be only one. I'm still working on something.

              I'd rather be phishing!

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              You could make a class inheriting from CMFCPropertyGridCtrl, say MaximilenMFCPropertyGridCtrl which only purpose is being a good friend of MyPropertyGrid.

              Veni, vidi, vici.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups