TlistView 控件是vcl 對windows公用控件庫的一個封裝
這樣就能繪制TlistView 的表頭了
一
以類名
二
這種方式實際上是通過發送消息來獲取表頭句柄
使用SetWindowLong這個API 就可以替換掉一個窗口的窗口過程
具體代碼
//
#ifndef Unit
#define Unit
//
#include
#include
#include
#include
#include
//
class TForm
{
__published: // IDE
TListView *ListView
private: // User declarations
public: // User declarations
__fastcall TForm
__fastcall~TForm
};
//
extern PACKAGE TForm
//
#endif
//
#include
#pragma hdrstop
#include
//
#pragma package(smart_init)
#pragma resource
TForm
typedef LRESULT(CALLBACK * TCallBack)(HWND
TCallBack g_oldListViewWndProc;
HWND g_hListViewHeader;
LRESULT CALLBACK ListViewWindowProc(HWND hwnd
LPARAM lParam)
{
PAINTSTRUCT ps ={
RECT rect = {
HDC hPen = NULL;
HDC hBrush = NULL;
int iCount =
int i
BYTE red
BYTE red
BYTE red
int j
switch(uMsg)
{
case WM_PAINT:
BeginPaint(g_hListViewHeader
hPen = SelectObject(ps
iCount = Header_GetItemCount(g_hListViewHeader); // 獲取表頭數目
// 本文轉自 C++Builder研究
SetDCPenColor(ps
red = GetRValue((TColor)(
green = GetGValue((TColor)(
blue = GetBValue((TColor)(
for (int i =
i
hBrush = SelectObject(ps
SetBkMode(ps
TextOut(ps
Form
Form
SelectObject(ps
}
hPen = SelectObject(ps
EndPaint(g_hListViewHeader
break;
default:
return CallWindowProc((FARPROC)g_oldListViewWndProc
uMsg
}
return
}
//
__fastcall TForm
{
g_hListViewHeader = FindWindowEx(ListView
NULL);
g_oldListViewWndProc = (TCallBack)GetWindowLong
(g_hListViewHeader
SetWindowLong(g_hListViewHeader
}
//
__fastcall TForm
{
SetWindowLong(g_hListViewHeader
}
From:http://tw.wingwit.com/Article/program/c/201311/11101.html