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.
???
Re: Subclassing , Message, And Overrides
Can you post the code for those 2 classes here ?
Re: Subclassing , Message, And Overrides
Open the CNewStatusBar implementation (.CPP) file and replace all CStatusBar with CMyStatusBar from which CNewStatusBar is derived.
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"]
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. :D ;)
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.
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
1 Attachment(s)
Re: Subclassing , Message, And Overrides
The CNewStatusbar is one of the files for CNewMenu created by Manfred Drasch
Here is the cpp attached.
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
Re: Subclassing , Message, And Overrides
Yes and Yes, so any ideas why the DrawItem is not called?
Re: Subclassing , Message, And Overrides
did you ever figure this out? I seem to have encountered the same problem.
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.