win32 sdk 列表视图控件绘制

92 篇文章 1 订阅
12 篇文章 0 订阅

微笑

 

//
LRESULT ListViewCustomDraw(HWND hwnd, LPARAM lParam)
{
	LPNMHDR pnmh = (LPNMHDR) lParam;
        
    if (pnmh->code != NM_CUSTOMDRAW) return 0;
		
	LPNMLVCUSTOMDRAW lpNMCustomDraw = (LPNMLVCUSTOMDRAW) lParam;

	int nResult = CDRF_DODEFAULT; 
	
	if (CDDS_PREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)
	{
		nResult = CDRF_NOTIFYITEMDRAW;
	}
	else if (CDDS_ITEMPREPAINT == lpNMCustomDraw->nmcd.dwDrawStage)
	{
		nResult = CDRF_NOTIFYSUBITEMDRAW;
	}
	else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == lpNMCustomDraw->nmcd.dwDrawStage)
	{
		nResult = CDRF_SKIPDEFAULT;
		
		const DWORD dwStyle = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS;
		
		HDC hdc = lpNMCustomDraw->nmcd.hdc; 
		SetBkMode(hdc,TRANSPARENT);
		int nItem = (int)lpNMCustomDraw->nmcd.dwItemSpec; 
		int nSubItem = lpNMCustomDraw->iSubItem; 
		
		BOOL bItemSelected = ListView_GetItemState(hwnd, nItem, LVIS_SELECTED);
		
		RECT subItemRect;
		ListView_GetSubItemRect(hwnd, nItem, nSubItem, LVIR_BOUNDS, &subItemRect);
//		
		HBRUSH brsh=0; 
		if (bItemSelected)
		{ 	//OutputDebugString("bItemSelected\n");
			brsh=CreateSolidBrush(RGB(255, 128, 128));//yellow
			FillRect(hdc, &subItemRect,brsh);
		}
		else
		{// not Selected
			brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));
			FillRect(hdc, &subItemRect,brsh);
		}
		if(brsh) DeleteObject(brsh);
//
		TCHAR szText[260];
		ListView_GetItemText(hwnd, nItem, nSubItem, szText, 260);
		DrawText(hdc, szText, strlen(szText), &subItemRect, dwStyle);
	}
	return nResult;
}


 

关键:
else
{// not Selected
brsh=CreateSolidBrush(RGB(51+nItem*30, 153, 255-nItem*30));
FillRect(hdc, &subItemRect,brsh);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值