123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #include "stdafx.h"
- #include "HeaderCtrlCl.h"
- IMPLEMENT_DYNAMIC(CHeaderCtrlCl, CHeaderCtrl)
- CHeaderCtrlCl::CHeaderCtrlCl()
- : m_R(171)
- , m_G(199)
- , m_B(235)
- , m_Gradient(8)
- {
- m_Format = "";
- m_Height = 1;
- m_fontHeight = 15;
- m_fontWith = 0;
- m_color = RGB(0,0,0);
- }
- CHeaderCtrlCl::~CHeaderCtrlCl()
- {
- }
- BEGIN_MESSAGE_MAP(CHeaderCtrlCl, CHeaderCtrl)
- ON_WM_PAINT()
- ON_MESSAGE(HDM_LAYOUT, OnLayout)
- END_MESSAGE_MAP()
- void CHeaderCtrlCl::OnPaint()
- {
- CPaintDC dc(this);
-
-
- int nItem;
- nItem = GetItemCount();
- for(int i = 0; i<nItem;i ++)
- {
- CRect tRect;
- GetItemRect(i,&tRect);
- int R = m_R,G = m_G,B = m_B;
- CRect nRect(tRect);
- nRect.left++;
-
- for(int j = tRect.top;j<=tRect.bottom;j++)
- {
- nRect.bottom = nRect.top+1;
- CBrush _brush;
- _brush.CreateSolidBrush(RGB(R,G,B));
- dc.FillRect(&nRect,&_brush);
- _brush.DeleteObject();
- R-=m_Gradient;G-=m_Gradient;B-=m_Gradient;
- if (R<0)R = 0;
- if (G<0)G = 0;
- if (B<0)B= 0;
- nRect.top = nRect.bottom;
- }
- dc.SetBkMode(TRANSPARENT);
- CFont nFont ,* nOldFont;
-
- dc.SetTextColor(m_color);
- nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));
- nOldFont = dc.SelectObject(&nFont);
- UINT nFormat = 1;
- if (m_Format[i]=='0')
- {
- nFormat = DT_LEFT;
- tRect.left+=3;
- }
- else if (m_Format[i]=='1')
- {
- nFormat = DT_CENTER;
- }
- else if (m_Format[i]=='2')
- {
- nFormat = DT_RIGHT;
- tRect.right-=3;
- }
- TEXTMETRIC metric;
- dc.GetTextMetrics(&metric);
- int ofst = 0;
- ofst = tRect.Height() - metric.tmHeight;
- tRect.OffsetRect(0,ofst/2);
- dc.DrawText(m_HChar[i],&tRect,nFormat);
- dc.SelectObject(nOldFont);
- nFont.DeleteObject();
- }
-
- CRect rtRect;
- CRect clientRect;
- GetItemRect(nItem - 1,rtRect);
- GetClientRect(clientRect);
- rtRect.left = rtRect.right+1;
- rtRect.right = clientRect.right;
- int R = m_R,G = m_G,B = m_B;
- CRect nRect(rtRect);
-
- for(int j = rtRect.top;j<=rtRect.bottom;j++)
- {
- nRect.bottom = nRect.top+1;
- CBrush _brush;
- _brush.CreateSolidBrush(RGB(R,G,B));
- dc.FillRect(&nRect,&_brush);
- _brush.DeleteObject();
- R-=m_Gradient;G-=m_Gradient;B-=m_Gradient;
- if (R<0)R = 0;
- if (G<0)G = 0;
- if (B<0)B= 0;
- nRect.top = nRect.bottom;
- }
- }
- LRESULT CHeaderCtrlCl::OnLayout( WPARAM wParam, LPARAM lParam )
- {
- LRESULT lResult = CHeaderCtrl::DefWindowProc(HDM_LAYOUT, 0, lParam);
- HD_LAYOUT &hdl = *( HD_LAYOUT * ) lParam;
- RECT *prc = hdl.prc;
- WINDOWPOS *pwpos = hdl.pwpos;
-
- int nHeight = (int)(pwpos->cy * m_Height);
- pwpos->cy = nHeight;
- prc->top = nHeight;
- return lResult;
- }
|