home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / daotable / listctrl.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  87 lines

  1. // ListCtrl.cpp : implementation file
  2. //
  3. // this class is an override of the default clistctrl
  4. // this version provides handlers to allow modifying the
  5. // subitem on repeated selection of the item in the list
  6.  
  7. // This is a part of the Microsoft Foundation Classes C++ library.
  8. // Copyright (C) 1992-1998 Microsoft Corporation
  9. // All rights reserved.
  10. //
  11. // This source code is only intended as a supplement to the
  12. // Microsoft Foundation Classes Reference and related
  13. // electronic documentation provided with the library.
  14. // See these sources for detailed information regarding the
  15. // Microsoft Foundation Classes product.
  16.  
  17. #include "stdafx.h"
  18. #include "DAOTable.h"
  19. #include "ListCtrl.h"
  20.  
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CFieldListCtrl
  29.  
  30. CFieldListCtrl::CFieldListCtrl()
  31. {
  32. }
  33.  
  34. CFieldListCtrl::~CFieldListCtrl()
  35. {
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CFieldListCtrl, CListCtrl)
  40.     //{{AFX_MSG_MAP(CFieldListCtrl)
  41.     ON_WM_LBUTTONDOWN()
  42.     //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CFieldListCtrl message handlers
  47.  
  48. // if you press the button over an item, then toggle the subitem
  49. // text between "", "ascending", and "descending" for index sort order
  50. // specification
  51. void CFieldListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
  52. {
  53.     // what item did we select
  54.     UINT flags;
  55.     int item = HitTest(point, &flags);
  56.  
  57.     // if an item is actually selected, then process
  58.     if (item != -1)
  59.     {
  60.         // get the item's current selection state based on subitem text
  61.         CString text = GetItemText(item, 1);
  62.  
  63.         // if selected, then modify the sub item text
  64.         if (text != "")
  65.         {
  66.             // if already ascending, then descending is next
  67.             if (text == _T("ascending"))
  68.             {
  69.                 SetItemText(item, 1, _T("descending"));
  70.                 SetItemState(item, 1, LVIS_SELECTED);
  71.                 CListCtrl::OnLButtonDown(nFlags, point);
  72.             }
  73.             else // descending goes to no selection or text
  74.             {
  75.                 SetItemText(item, 1, _T(""));
  76.                 SetItemState(item, 0, LVIS_SELECTED);
  77.             }
  78.         }
  79.         else // if no selection at all, then 1st state is ascending
  80.         {
  81.             SetItemText(item, 1, _T("ascending"));
  82.             SetItemState(item, 1, LVIS_SELECTED);
  83.             CListCtrl::OnLButtonDown(nFlags, point);
  84.         }
  85.     }
  86. }
  87.