1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// <a href="http://www.ccrun.com/article.asp?i=1069&d=uq3568" target="_blank">http://www.ccrun.com/article.asp?i=1069&d=uq3568</a>
typedef LRESULT(CALLBACK * TCallBack)(HWND, UINT, WPARAM, LPARAM);
TCallBack g_oldListViewWndProc;
HWND g_hListViewHeader;
LRESULT CALLBACK ListViewWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps ={ 0 };
RECT rect = { 0 };
HDC hPen = NULL;
HDC hBrush = NULL;
int iCount = 0;
int i1 = 0;
BYTE red0 = 115, green0 = 154, blue0 = 206;
BYTE red1 = 255, green1 = 255, blue1 = 255;
BYTE red, green, blue;
int j, m, n;
switch(uMsg)
{
case WM_PAINT:
BeginPaint(g_hListViewHeader, &ps);
hPen = SelectObject(ps.hdc, GetStockObject(DC_PEN));
iCount = Header_GetItemCount(g_hListViewHeader); // ??????
// ???? C++Builder?? - <a href="http://www.ccrun.com/article.asp?i=1069&d=uq3568" target="_blank">http://www.ccrun.com/article.asp?i=1069&d=uq3568</a>
SetDCPenColor(ps.hdc, ColorToRGB((TColor)(0x00EFDBCE)));
red = GetRValue((TColor)(0x00EFDBCE));
green = GetGValue((TColor)(0x00EFDBCE));
blue = GetBValue((TColor)(0x00EFDBCE));
for (int i = 0; i < iCount; i++)
{
Header_GetItemRect(g_hListViewHeader, i, &rect); // ??Item???
m = rect.bottom - rect.top;
n = m / 2 + 1;
for (j = 0; j < n; j++)
{
red = red0 * (j + 1) / n + red1 * (n - j - 1) / n;
green = green0 * (j + 1) / n + green1 * (n - j - 1) / n;
blue = blue0 * (j + 1) / n + blue1 * (n - j - 1) / n;
SetDCPenColor(ps.hdc, RGB(red, green, blue));
MoveToEx(ps.hdc, rect.left + 1, rect.top + j, NULL);
LineTo(ps.hdc, rect.right, rect.top + j);
MoveToEx(ps.hdc, rect.left + 1, rect.bottom - j - 1, NULL);
LineTo(ps.hdc, rect.right, rect.bottom - j - 1);
}
SetDCPenColor(ps.hdc, ColorToRGB(clBtnFace));
MoveToEx(ps.hdc, rect.right, rect.top + 1, NULL);
LineTo(ps.hdc, rect.right, rect.bottom - 1);
SelectObject(ps.hdc, Form1->Font->Handle);
i1 = ((rect.bottom - rect.top) - abs(Form1->Font->Height)) / 2;
hBrush = SelectObject(ps.hdc, GetStockObject(NULL_BRUSH));
SetBkMode(ps.hdc, TRANSPARENT); // ??????????
TextOut(ps.hdc, rect.left + 10, rect.top + i1,
Form1->ListView1->Columns->Items[i]->Caption.c_str(),
Form1->ListView1->Columns->Items[i]->Caption.Length());
SelectObject(ps.hdc, hBrush);
}
hPen = SelectObject(ps.hdc, hPen);
EndPaint(g_hListViewHeader, &ps);
break;
default:
return CallWindowProc((FARPROC)g_oldListViewWndProc, g_hListViewHeader,
uMsg, wParam, lParam);
}
return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
g_hListViewHeader = FindWindowEx(ListView1->Handle, NULL, "SysHeader32", NULL);
g_oldListViewWndProc = (TCallBack)GetWindowLong
(g_hListViewHeader, GWL_WNDPROC);
SetWindowLong(g_hListViewHeader, GWL_WNDPROC, long(ListViewWindowProc));
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
SetWindowLong(g_hListViewHeader, GWL_WNDPROC, (long)g_oldListViewWndProc);
} |
Partager