ListCtrlEx.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /******************************************************************************\
  2. * file : ListCtrl.h
  3. * created: 1997.09.22
  4. *
  5. * description:
  6. * Implements a CListCtrl which can mark full rows.
  7. \******************************************************************************/
  8. #ifndef _CLISTCTRLEX_H_
  9. #define _CLISTCTRLEX_H_
  10. #include "TitleTip.h"
  11. #define LVNU_SELCHANGED 0x1000
  12. /**
  13. * A super CListControl.
  14. * <P>features:
  15. * <UL>
  16. * <LI>Title Tip item expantion
  17. * <LI>full row selection
  18. * <LI>notifies parent selection has changed
  19. * <LI>
  20. * </UL>
  21. */
  22. class CListCtrlEx : public CListCtrl
  23. {
  24. typedef CListCtrl inherited;
  25. DECLARE_DYNCREATE(CListCtrlEx)
  26. // Construction
  27. public:
  28. CListCtrlEx();
  29. virtual ~CListCtrlEx();
  30. // Attributes
  31. protected:
  32. BOOL m_bFullRowSel;
  33. BOOL m_bClientWidthSel;
  34. bool bShowLine;
  35. int nFontHeight;
  36. COLORREF nTxtColor;
  37. public:
  38. BOOL SetFullRowSel(BOOL bFillRowSel);
  39. BOOL GetFullRowSel();
  40. void ShowLineBk( bool bShow )
  41. {
  42. bShowLine = bShow;
  43. };
  44. void SetTxtColor( COLORREF cr )
  45. {
  46. nTxtColor = cr;
  47. }
  48. void SetFontHeight( int nNewFontHeight )
  49. {
  50. nFontHeight = nNewFontHeight;
  51. /*
  52. CFont *pOldFont = NULL;
  53. CFont font;
  54. if( nFontHeight != -1 )
  55. {
  56. CFont* ptf = GetFont(); // 得到原来的字体
  57. LOGFONT lf;
  58. ptf->GetLogFont(&lf);
  59. lf.lfHeight = nFontHeight; // 改变字体高度
  60. CDC* pDC = GetDC();
  61. font.CreateFontIndirect(&lf);
  62. pOldFont = (CFont *)pDC->SelectObject(&font);
  63. font.DeleteObject();
  64. ReleaseDC( pDC );
  65. }
  66. //*/
  67. CRect rc;
  68. GetWindowRect( &rc );
  69. WINDOWPOS wp;
  70. wp.hwnd = m_hWnd;
  71. wp.cx = rc.Width();
  72. wp.cy = rc.Height();
  73. wp.flags = SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
  74. SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );
  75. };
  76. // Overrides
  77. protected:
  78. virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  79. // ClassWizard generated virtual function overrides
  80. //{{AFX_VIRTUAL(CListCtrlEx)
  81. public:
  82. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  83. protected:
  84. virtual void PreSubclassWindow();
  85. //}}AFX_VIRTUAL
  86. // Implementation
  87. public:
  88. #ifdef _DEBUG
  89. virtual void Dump(CDumpContext& dc) const;
  90. #endif
  91. protected:
  92. void RepaintSelectedItems();
  93. // Implementation - list view colors
  94. COLORREF m_clrText;
  95. COLORREF m_clrTextBk;
  96. COLORREF m_clrBkgnd;
  97. CTitleTip m_titletip;
  98. afx_msg LRESULT OnSetTextColor(WPARAM wParam, LPARAM lParam);
  99. afx_msg LRESULT OnSetTextBkColor(WPARAM wParam, LPARAM lParam);
  100. afx_msg LRESULT OnSetBkColor(WPARAM wParam, LPARAM lParam);
  101. bool HitTestRowCol(CPoint& point, int& iRow, int& iColumn)const;
  102. CRect GetCellRect(int iRow, int iColumn)const;
  103. int GetTrueColumnWidth(int nCurrentPosition)const;
  104. CString GetTrueItemText(int row, int col)const;
  105. void HideTitleTip();
  106. void SendSelChangedNotification();
  107. void ShowTitleTip(CPoint point);
  108. // Generated message map functions
  109. protected:
  110. //{{AFX_MSG(CListCtrlEx)
  111. afx_msg void OnPaint();
  112. afx_msg void OnSetFocus(CWnd* pOldWnd);
  113. afx_msg void OnKillFocus(CWnd* pNewWnd);
  114. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  115. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  116. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  117. afx_msg void OnDestroy();
  118. afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  119. afx_msg void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
  120. //}}AFX_MSG
  121. DECLARE_MESSAGE_MAP()
  122. };
  123. /////////////////////////////////////////////////////////////////////////////
  124. #endif