在LISTCTRL里INSERTCOLUMN 2 列 把第一列背景设为黑色而第二列设为白色
有什么简单办法?
有什么简单办法?
解决方案 »
- CMultiDocTemplate使用问题
- 新手请教:WM_Onchar 必须在view类中才能响应吗
- 怎样打开一个HTML文件(也包括txt)进行编辑,然后保存?
- 如何打开一个文件??用MFC
- 想在对话框上画个二维曲线,应该朝哪个方向努力?
- vc传送消息时怎么样获得子窗口的句柄?
- 是不是我的VC6还有什么地方设置有问题?
- 如何判断当前窗口句柄不是控件窗口(按钮控件,树型控件等等)
- 调查 :openCV 创建的窗口 没有带滚动条 晨宇思远 写了一个程序你们跑通了吗
- 向您求教:“{”和“}”........
- 如何得到几个月后的日期?谢谢
- 如何隐藏我调用别的应用程序的窗口?(高手快来拿分,另祝大家中秋快乐)
把第一列背景设为黑色而第二列设为白色
wuxuan(真心英雄): 有点烦
1
Create the MFC project with view as ListView.
2
Apply styles to the view .cpp file.
BOOL CMyListView::PreCreateWindow(CREATESTRUCT& cs)
{
//adding styles
cs.style |= LVS_REPORT;
return CListView::PreCreateWindow(cs);
}3
Add columns to the view .cpp file.
void CMyListView::OnInitialUpdate()
{
CListView::OnInitialUpdate(); CListCtrl& ListCtrl = GetListCtrl(); //inserting 5 cols
ListCtrl.InsertColumn(0, "Col-1", LVCFMT_LEFT, 75);
ListCtrl.InsertColumn(1, "Col-2", LVCFMT_LEFT, 100);
ListCtrl.InsertColumn(2, "Col-3", LVCFMT_LEFT, 100);
ListCtrl.InsertColumn(3, "Col-4", LVCFMT_LEFT, 100);
ListCtrl.InsertColumn(4, "Col-5", LVCFMT_LEFT, 100); //adding 10 items
CString item;
for(int i=0;i<10;i++)
{
item.Format("Item-%d",i);
ListCtrl.InsertItem(i,item);
}
}4
Add the following line to the message map area of the view header(.h) file.
afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT*
pResult);5
Add the following line to the message map area of the view .cpp file.
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)6
Add the OnCustomDraw function.
void CMyListView::OnCustomDraw(NMHDR* pNMHDR,
LRESULT* pResult)
{
*pResult = 0; COLORREF dwColourTxt = 0;
COLORREF dwColourBk = RGB(255, 255, 255); LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR; switch(lplvcd->nmcd.dwDrawStage)
{
Case CDDS_PREPAINT:
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
} // Modify item text and or background
Case CDDS_ITEMPREPAINT:
{
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourTxt = RGB(255, 0, 0); // Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourTxt = RGB(0, 255, 0); // Green
}
Else
{
dwColourTxt = RGB(0, 0, 255); // Blue
}
lplvcd->clrText = dwColourTxt;
// If you want the sub items the same as
// the item, set *pResult to CDRF_NEWFONT
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
} // Modify sub item text and or background
case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
// Ignore the first sub item; it is the item
// handled above
if(lplvcd->iSubItem != 0)
{
// First sub item
if(lplvcd->iSubItem == 1)
{
dwColourTxt = RGB(0, 127, 127);
// Pale blue
dwColourBk = RGB(255, 255, 255);
// White
}
// All sub items after the first
Else
{
dwColourTxt = RGB(255, 255, 255);
// White
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourBk = RGB(255, 0, 102);
// Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourBk = RGB(204, 255, 153);
// Green
}
Else
{
dwColourBk = RGB(0, 102, 204);
// Blue
}
}
lplvcd->clrText = dwColourTxt;
lplvcd->clrTextBk = dwColourBk;
}
*pResult = CDRF_NEWFONT;
return;
}
}
}