ListCtrlH.h 3.4 KB

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