user1711993
user1711993

Reputation: 271

Changing default sort arrows of CMFCListCtrl

I found a problem. I can't change default sort arrows in header of CMFCListCtrl. I found post on msdn about CMFCHeaderCtrl::OnDrawSortArrow but it didn't help because no examples there.

I tried simple method how I set arrows to CListCtrl header through the CimageList and HDITEM but those arrow sets only to left side because right side has already arrow default.

Google is empty on solutions how change default arrows on CMFCListCTrl.

Please help me) Thanks! PS. Please note that this is CMFCListCtrl not a CListCtrl where I can add arrows very easly.

Upvotes: 0

Views: 1143

Answers (2)

larsilund
larsilund

Reputation: 1

The CMFCHeaderCtrl calls the currently active Visual Manager to do the actual drawing of sort arrows. It is easy to implement a customized Visual manager which overrides the arrow drawing method in the base class.

class CMyVisualManager:public CMFCVisualManagerOffice2007
{
    virtual void OnDrawHeaderCtrlSortArrow(CMFCHeaderCtrl* pCtrl, CDC* pDC, CRect& rect, BOOL bIsUp);
};


void CMyVisualManager::OnDrawHeaderCtrlSortArrow(CMFCHeaderCtrl* pCtrl, CDC* pDC, CRect& rectArrow, BOOL bIsUp)
{
   BOOL bDlgCtrl = pCtrl->IsDialogControl();

   CPen penDark(PS_SOLID, 1, bDlgCtrl ? afxGlobalData.clrBtnDkShadow : afxGlobalData.clrBarDkShadow);

   CPen* pPenOld = pDC->SelectObject(&penDark);;
   ASSERT_VALID(pPenOld);

   if (!bIsUp)
   {
      pDC->MoveTo(rectArrow.CenterPoint().x, rectArrow.bottom);
      pDC->LineTo(rectArrow.CenterPoint().x, rectArrow.top);

      pDC->MoveTo(rectArrow.CenterPoint().x-2, rectArrow.top+4);
      pDC->LineTo(rectArrow.CenterPoint().x+3, rectArrow.top+4);

      pDC->MoveTo(rectArrow.CenterPoint().x-1, rectArrow.top+3);
      pDC->LineTo(rectArrow.CenterPoint().x+2, rectArrow.top+3);
      pDC->MoveTo(rectArrow.CenterPoint().x-1, rectArrow.top+2);
      pDC->LineTo(rectArrow.CenterPoint().x+2, rectArrow.top+2);
   }
   else
   {
      pDC->MoveTo(rectArrow.CenterPoint().x, rectArrow.top);
      pDC->LineTo(rectArrow.CenterPoint().x, rectArrow.bottom);

      pDC->MoveTo(rectArrow.CenterPoint().x-2, rectArrow.bottom-4);
      pDC->LineTo(rectArrow.CenterPoint().x+3, rectArrow.bottom-4);

      pDC->MoveTo(rectArrow.CenterPoint().x-1, rectArrow.bottom-3);
      pDC->LineTo(rectArrow.CenterPoint().x+2, rectArrow.bottom-3);
      pDC->MoveTo(rectArrow.CenterPoint().x-1, rectArrow.bottom-2);
      pDC->LineTo(rectArrow.CenterPoint().x+2, rectArrow.bottom-2);
   }

   pDC->SelectObject(pPenOld);
}

Upvotes: 0

xMRi
xMRi

Reputation: 15375

Because CMFCHeaderCtrl is a member inside CMFCListCtrl you can not overwrite it. Try to derive yor own CMFCListCtrl class, with your own CMFCHeaderCtrl class, that overwrites OnDrawSortHeader OnDrawSortArrow. Overwrite CMFCListCtrl::InitHeader and subclass to your header control class.

If you start form scratch with a CListCtrl you can directly subclass the header control. The complete stuff inside CMFCListCtrl isn't so complicated and easy to reimplement. Depends what functionality you need.

Upvotes: 2

Related Questions