home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c06 / tabbed / clrlstbx.cpp next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  1.8 KB  |  74 lines

  1. // ClrLstBx.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Tabbed.h"
  6. #include "ClrLstBx.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CColorListBox
  16.  
  17. CColorListBox::CColorListBox()
  18. {
  19. }
  20.  
  21. CColorListBox::~CColorListBox()
  22. {
  23. }
  24.  
  25. void CColorListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
  26. {
  27.     CRect rect;
  28.     GetClientRect(&rect);
  29.  
  30.     // For this to work the original list box as drawn in
  31.     // the resource editor must have the OwnerDraw property
  32.     // set to variable, not fixed, even though we're drawing
  33.     // them all the same height.
  34.     lpMIS->itemHeight = rect.Height() / 4;
  35.     lpMIS->itemWidth = rect.Width();
  36. }
  37.  
  38. void CColorListBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
  39. {
  40.     CDC* pDC = CDC::FromHandle(lpDIS->hDC);
  41.     
  42.     // Because this is an owner draw list box, the AddString
  43.     // function has placed an RGB value in item data.
  44.     COLORREF cr = (COLORREF)lpDIS->itemData;
  45.     
  46.     // There are 3 states this function accomodates.
  47.     // 1) When the item is originally drawn.
  48.     if (lpDIS->itemAction & ODA_DRAWENTIRE)
  49.     {
  50.         CBrush br(cr);
  51.         pDC->FillRect(&lpDIS->rcItem, &br);
  52.     }
  53.  
  54.     // 2) When its selection state is changing from non-selected
  55.     //    to selected, so we hilite its frame.
  56.     if ((lpDIS->itemState & ODS_SELECTED) &&
  57.         (lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
  58.     {
  59.         COLORREF crHilite = RGB(255-GetRValue(cr),
  60.                         255-GetGValue(cr), 255-GetBValue(cr));
  61.         CBrush br(crHilite);
  62.         pDC->FrameRect(&lpDIS->rcItem, &br);
  63.     }
  64.  
  65.     // 3) When the item was selected and it's been de-selected.
  66.     //    We need to remove its frame.
  67.     if (!(lpDIS->itemState & ODS_SELECTED) &&
  68.         (lpDIS->itemAction & ODA_SELECT))
  69.     {
  70.         CBrush br(cr);
  71.         pDC->FrameRect(&lpDIS->rcItem, &br);
  72.     }
  73. }
  74.