-
August 10th, 2004, 05:24 PM
#1
Multiple inheritance for a CListCtrl
I have an application that uses CListCtrls.
Requirement 1 is to have a list control that uses alternating colors for different rows
Requirement 2 is to be able to print the list control.
I've found classes on codeguru that fulfill the 2 requirements independently....but not a class that does both.
Say I have CColorListCtrl and CPrintListCtrl that provides the different functions.
Can I create a class CColorPrintListCtrl that inherits from both CColorListCtrl and CPrintListCtrl ? Will multiple inheritance work here?
Thanks,
Mdd
-
August 10th, 2004, 10:46 PM
#2
Step 1 is simple task. In your CListCtrl derive class (for e.g. the class that prints your clistctrl), You can do something like
Code:
void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;
int iRow = lplvcd->nmcd.dwItemSpec;
switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYSUBITEMDRAW; // CMT: ask for subitem notifications.
break;
case CDDS_ITEMPREPAINT:
if (iRow %2 == 0) // for alternate row
{
// CMT: Initializes a CFont object with the specified characteristics.
SelectObject (lplvcd->nmcd.hdc, m_HeaderFont);
lplvcd->clrText = m_colorText;
lplvcd->clrTextBk = m_colorBackground;
*pResult = CDRF_NEWFONT;
}
break;
default: // CMT: it wasn't a notification that was interesting to us.
*pResult = CDRF_DODEFAULT;
}
}
-
August 11th, 2004, 04:00 AM
#3
I think you should not use multiple inheritance with MFC.
TN016: Using C++ Multiple Inheritance with MFC
But see specifically this:
From MSDN
In order for the MFC message map system to work correctly, there are two additional requirements:
There must be only one CWnd-derived base class.
The CWnd-derived base class must be the first (or left-most) base class
Extreme situations require extreme measures
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|