// do we want to do any drawing after
// the list control is finished
virtual bool IsSubItemPostDraw()
// if we are doing the drawing afterwards ourselves
// override and put the code in here
// the return value is not used here
virtual bool OnSubItemPostDraw(CDC* /*pDC*/,
int /*nItem*/,
int /*nSubItem*/,
UINT /*nState*/,
LPARAM /*lParam*/)
There is quite a bit of code here as well. Again, there is good new. Each of the virtual functions performs a simple and well-defined task. The OnCustomdraw function does all the housework and ties everything together.
Well, that about wraps it up for our CListCtrlWithCustomDraw class. The last step is to derive a class from CListCtrlWithCustomDraw.
Using the CListCtrlWithCustomDraw Class
Again, we can use the WizardBar to create a new class. And as before it can be done with a little hacking. Start off by defining a class call CMyListCtrl, and say that it is an MFC class derived from CListCtrl. Then edit the .h and .cpp files that are generated, change all occurrences of CListCtrl to CListCtrlWithCustomDraw, and finally add a #include "ListCtrlWithCustomDraw.h" line to the .h file, just before the class declaration. Once you have the skeleton CMyListCtrl, we can override some of the virtual functions to change the appearance of the control.
评论