Subclassing , Message, And Overrides
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: Subclassing , Message, And Overrides

  1. #1
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Subclassing , Message, And Overrides

    My scenario is this:

    I have a CMyStatusBar calss from CStatusbar to implement pane clicks and drawing bitmaps in two fo the panes. The bitmaps are drawn using bitblt in the DrawItem override and this has always worked.

    //in Mainfrm.h
    CMyStatusBar m_wndMyStatusBar;

    I have now added another CNewStatusbar class derived from CStatusbar and made CMystatusbar inherit from CNewStatusbar.

    It compiles fine but now DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) in CMyStatusBar is not called. I even put it in the CNewStatusBar class and it is not called there either.

    Why is DrawItem no longer called? My click routines still function normally.

    I thought maybe the Paint() override in the CNewStatusbar class was wiping out the bitmaps or something but found by putting break points in DrawItem() that it is not even called on creation.

    ???

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Subclassing , Message, And Overrides

    Can you post the code for those 2 classes here ?
    Regards,
    Ramkrishna Pawar

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Subclassing , Message, And Overrides

    Open the CNewStatusBar implementation (.CPP) file and replace all CStatusBar with CMyStatusBar from which CNewStatusBar is derived.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Subclassing , Message, And Overrides

    Quote Originally Posted by ovidiucucu
    Open the CNewStatusBar implementation (.CPP) file and replace all CStatusBar with CMyStatusBar from which CNewStatusBar is derived.
    But isn't OP's CMyStatusBar already derived from CNewStatusBar ???

    CStatusBar==> CNewStatusbar==>CMyStatusbar...is this correct ?

    [Note:==> means "is a base class of"]
    Regards,
    Ramkrishna Pawar

  5. #5
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Subclassing , Message, And Overrides

    Quote Originally Posted by Krishnaa
    But isn't OP's CMyStatusBar already derived from CNewStatusBar ???

    CStatusBar==> CNewStatusbar==>CMyStatusbar...is this correct ?

    [Note:==> means "is a base class of"]
    Possible to be necessary shuffling the cards again.
    However, I think my ideea was clear: most possible, the OP replaced base class CStatusBar in the class definition, but forgot to do the same in the implementation file.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  6. #6
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Re: Subclassing , Message, And Overrides

    Yes its

    CStatusBar==> CNewStatusbar==>CMyStatusbar...

    And I already replaced all the CStatusbar in CMyStatusbar with CNewStatusbar.

    However, when I change this:

    Code:
     
    IMPLEMENT_DYNCREATE(CMyStatusBar, CNewStatusBar)
    
    BEGIN_MESSAGE_MAP(CMyStatusBar, CNewStatusBar)
    	ON_WM_CREATE()
    	ON_WM_DESTROY()
    	ON_WM_LBUTTONUP()
    	ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateIndicatorTime)
    END_MESSAGE_MAP()

    back to this:


    Code:
     
    IMPLEMENT_DYNCREATE(CMyStatusBar, CStatusBar)
    
    BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
    	ON_WM_CREATE()
    	ON_WM_DESTROY()
    	ON_WM_LBUTTONUP()
    	ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateIndicatorTime)
    END_MESSAGE_MAP()
    The DrawItem() is called again.

    So I'm wondering if the problem is in the CNewStatusbar

  7. #7
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Re: Subclassing , Message, And Overrides

    The CNewStatusbar is one of the files for CNewMenu created by Manfred Drasch

    Here is the cpp attached.
    Attached Files Attached Files

  8. #8
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,059

    Re: Subclassing , Message, And Overrides

    If CStatusBar==> CNewStatusbar==>CMyStatusbar...

    Then you must have:

    Code:
    BEGIN_MESSAGE_MAP(CNewStatusBar, CStatusBar)
    and
    Code:
    BEGIN_MESSAGE_MAP(CMyStatusbar, CNewStatusBar)
    and generally
    Code:
    BEGIN_MESSAGE_MAP(theClass, baseClass)
    where
    • theClass - specifies the name of the class whose message map this is
    • baseClass - specifies the name of the base class of theClass
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  9. #9
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Re: Subclassing , Message, And Overrides

    Yes and Yes, so any ideas why the DrawItem is not called?

  10. #10
    Join Date
    Jul 2011
    Posts
    1

    Question Re: Subclassing , Message, And Overrides

    did you ever figure this out? I seem to have encountered the same problem.

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Subclassing , Message, And Overrides

    Well, if you have "the same problem" as OP and none from the provided hints ahs help you, please, show your code (with code tags) and the full problem description.
    Victor Nijegorodov

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

This is a CodeGuru survey question.


Featured


HTML5 Development Center