根据他们帮助文档,对于下面这个给表格设置背景颜色和字体颜色这个操作步骤不明白,请能详细说下怎么去重载这个函数,希望能说下操作的步骤
If we want to change the foreground/background color or the font style (bold, italic, underline), then we can override the methods CGridListCtrlEx::OnDisplayCellColor() and CGridListCtrlEx::OnDisplayCellFont().
bool MyGridCtrl::OnDisplayCellColor(int nRow, int nCol, COLORREF& textColor, COLORREF& backColor)
{
if (nRow == 3 && nCol == 3)
{
textColor = RGB(0,255,0);
backColor = RGB(0,0,255);
return true; // I want to override the color of this cell
}
return false; // Use default color
}
------解决思路----------------------
取值判断为 cpp -> CGridListCtrlEx.cpp
鼠标所在当前行:pLVCD->nmcd.dwItemSpec;
鼠标所在当前列:int nCol = pLVCD->iSubItem;
bool CGridListCtrlEx::OnDisplayCellColor(NMLVCUSTOMDRAW* pLVCD)
{
int nRow = (int)pLVCD->nmcd.dwItemSpec;
int nCol = pLVCD->iSubItem;
LPARAM nItemData = pLVCD->nmcd.lItemlParam;
(nItemData); // Avoid unreferenced variable warning
return OnDisplayCellColor(nRow, nCol, pLVCD->clrText, pLVCD->clrTextBk);
}
我没测试 这是事件 具体请你自己去测试 可以找鼠标单击的事件函数在逐一写代码.
------解决思路----------------------
通过搜索可以看到 第一个Call OnDisplayCellColor
bool CGridListCtrlEx::OnDisplayCellColor(int nRow, int nCol, COLORREF& textColor, COLORREF& backColor)
{
return false;
}
是个空程序
在里面做事情就行了.
------解决思路----------------------
bool CGridListCtrlEx::OnDisplayCellColor(NMLVCUSTOMDRAW* pLVCD)
{
int nRow = (int)pLVCD->nmcd.dwItemSpec;
int nCol = pLVCD->iSubItem;
LPARAM nItemData = pLVCD->nmcd.lItemlParam;
(nItemData); // Avoid unreferenced variable warning
return OnDisplayCellColor(nRow, nCol, pLVCD->clrText, pLVCD->clrTextBk);
}
//------------------------------------------------------------------------
//! Override this method to change the colors used for drawing a cell
//!
//! @param nRow The index of the row
//! @param nCol The index of the column
//! @param textColor The text color used when drawing the cell
//! @param backColor The background color when drawing the cell
//! @return Color is overrided
//------------------------------------------------------------------------
bool CGridListCtrlEx::OnDisplayCellColor(int nRow, int nCol, COLORREF& textColor, COLORREF& backColor)
{
if(nRow == 0 && nCol == 3){ //判断第一行 第三列
textColor = RGB(200,5,5);
backColor = RGB(250,240,210);
}
if(nRow == 1 && nCol == 2){
textColor = RGB(255,10,10);
backColor = RGB(235,235,230);
}
return false;
}
------解决思路----------------------
我是新手还望楼主指教最近也在研究这个 拓展类 有兴趣可以加我qq 540163 一起学习!