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

    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

  2. #2
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211
    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;
    	}
    }

  3. #3
    Join Date
    Apr 2003
    Location
    Athens, Greece
    Posts
    1,094
    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
  •  





Click Here to Expand Forum to Full Width

Featured