123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #include "stdafx.h"
- #include "HeaderCtrlEx.h"
- IMPLEMENT_DYNAMIC(CHeaderCtrlEx, CHeaderCtrl)
- CHeaderCtrlEx::CHeaderCtrlEx()
- {
- }
- CHeaderCtrlEx::~CHeaderCtrlEx()
- {
- }
- BEGIN_MESSAGE_MAP(CHeaderCtrlEx, CHeaderCtrl)
- ON_WM_PAINT()
- ON_MESSAGE(HDM_LAYOUT, OnLayout)
- END_MESSAGE_MAP()
- LRESULT CHeaderCtrlEx::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 = 35;
- pwpos->cy = nHeight;
- prc->top = nHeight;
- return lResult;
- }
- void CHeaderCtrlEx::OnPaint()
- {
- CPaintDC dc(this);
-
- RECT rRect;
- GetClientRect(&rRect);
- int nWidth = rRect.right-rRect.left;
- int nHeight = rRect.bottom-rRect.top;
- CDC memDC;
- CBitmap memBitmap;
- CBrush brush;
-
- memDC.CreateCompatibleDC(&dc);
- memBitmap.CreateCompatibleBitmap(&dc, nWidth, nHeight);
- memDC.SelectObject(&memBitmap);
- memDC.SetBkMode(TRANSPARENT);
-
- CFont font;
- font.CreateFont(-MulDiv(int(21), 72, 72),
- 0, 0, 0, FW_NORMAL, 0, 0, 0, GB2312_CHARSET,
- OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, PROOF_QUALITY,
- FIXED_PITCH | FF_SWISS, "微软雅黑");
- memDC.SelectObject(&font);
- TRIVERTEX vert[2] ;
- GRADIENT_RECT gRect;
- vert [0] .x = rRect.left;
- vert [0] .y = rRect.top;
- vert [1] .x = rRect.right;
- vert [1] .y = rRect.bottom;
- vert [0] .Red = 0xff00;
- vert [0] .Green = 0xff00;
- vert [0] .Blue = 0xff00;
- vert [0] .Alpha = 0x0000;
- vert [1] .Red = 0x9100;
- vert [1] .Green = 0xd100;
- vert [1] .Blue = 0xf300;
- vert [1] .Alpha = 0xff00;
- gRect.UpperLeft = 0;
- gRect.LowerRight = 1;
- memDC.GradientFill(vert,2,&gRect,1,GRADIENT_FILL_RECT_V);
-
- int nCount = GetItemCount();
- for (int i =0; i < nCount; i++)
- {
- CRect itemRc;
- GetItemRect(i, &itemRc);
- CRect txtRc= itemRc;
- txtRc.left+=5;
-
- HDITEM Item={0};
- TCHAR lpBuffer[256] = {0};
- Item.cchTextMax = 256;
- Item.pszText = lpBuffer;
- Item.mask = HDI_TEXT;
- GetItem(i, &Item);
- memDC.DrawText(lpBuffer, txtRc, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
-
- CPen pen;
- pen.CreatePen(PS_SOLID, 1, 0xFFE4E1);
- memDC.SelectObject(&pen);
- memDC.MoveTo(itemRc.right, itemRc.top);
- memDC.LineTo(itemRc.right, itemRc.bottom);
- pen.DeleteObject();
- pen.CreatePen(PS_SOLID, 1, 0xFFFFFF);
- memDC.SelectObject(&pen);
- memDC.MoveTo(itemRc.right+1, itemRc.top);
- memDC.LineTo(itemRc.right+1, itemRc.bottom);
- }
-
- CPen pen;
- pen.CreatePen(PS_SOLID, 1,0xFFE4E1);
- memDC.SelectObject(&pen);
- memDC.MoveTo(rRect.left, rRect.bottom-1);
- memDC.LineTo(rRect.right, rRect.bottom-1);
- pen.DeleteObject();
-
-
-
-
- dc.BitBlt(0,0, nWidth, nHeight, &memDC, 0, 0, SRCCOPY);
- ReleaseDC(&memDC);
- }
- BOOL CHeaderCtrlEx::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
- {
-
- return CHeaderCtrl::Create(dwStyle, rect, pParentWnd, nID);
- }
|