skin++就是那个界面库了。自绘clistctrl,通过ondrawitem改变背景、字体、颜色等。光用skin++是正常的。
光用自绘clistctrl,也是正常的。
但两个一起用,自绘clistctrl里面其他的也正常,就是不显示字了,行也还是有的,都能选中。skin++有个通过m_hwnd设置不使用skin的方法,但只针对m_hwnd窗口本身,不涉及子窗口。对clistctrl.m_hwnd设置也自然没用了。效果图:
代码如下:void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{ // TODO: 添加您的代码以绘制指定项
TCHAR lpBuffer[256]; LV_ITEM lvi; lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi)); LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT; CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rtClient;
GetClientRect(&rtClient);
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left;
} CRect rcItem;
if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))
continue; ::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CRect rcTemp;
rcTemp = rcItem; if (nCol==0)
{
rcTemp.left -=2;
} if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
COLORREF color;
color = GetBkColor();
pDC->FillSolidRect(rcTemp,color); if (FindColColor(nCol,color))
{
pDC->FillSolidRect(rcTemp,color);
}
if (FindItemColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->FillSolidRect(rcTemp,color);
}
//pDC->SetTextColor(m_color);
} pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); UINT uFormat = DT_CENTER ;
if (m_Header.m_Format[nCol]=='0')
{
uFormat = DT_LEFT;
}
else if (m_Header.m_Format[nCol]=='1')
{
uFormat = DT_CENTER;
}
else if (m_Header.m_Format[nCol]=='2')
{
uFormat = DT_RIGHT;
}
TEXTMETRIC metric;
pDC->GetTextMetrics(&metric);
int ofst;
ofst = rcItem.Height() - metric.tmHeight;
rcItem.OffsetRect(0,ofst/2);
pDC->SetTextColor(m_color);
COLORREF color;
if (FindColTextColor(nCol,color))
{
pDC->SetTextColor(color);
}
if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->SetTextColor(color);
}
CFont nFont ,* nOldFont;
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体
nOldFont = pDC->SelectObject(&nFont);
DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&rcItem, uFormat) ; pDC->SelectStockObject(SYSTEM_FONT) ;
}}
光用自绘clistctrl,也是正常的。
但两个一起用,自绘clistctrl里面其他的也正常,就是不显示字了,行也还是有的,都能选中。skin++有个通过m_hwnd设置不使用skin的方法,但只针对m_hwnd窗口本身,不涉及子窗口。对clistctrl.m_hwnd设置也自然没用了。效果图:
代码如下:void CListCtrlCl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{ // TODO: 添加您的代码以绘制指定项
TCHAR lpBuffer[256]; LV_ITEM lvi; lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = lpDrawItemStruct->itemID ;
lvi.iSubItem = 0;
lvi.pszText = lpBuffer ;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi)); LV_COLUMN lvc, lvcprev ;
::ZeroMemory(&lvc, sizeof(lvc));
::ZeroMemory(&lvcprev, sizeof(lvcprev));
lvc.mask = LVCF_WIDTH | LVCF_FMT;
lvcprev.mask = LVCF_WIDTH | LVCF_FMT; CDC* pDC;
pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rtClient;
GetClientRect(&rtClient);
for ( int nCol=0; GetColumn(nCol, &lvc); nCol++)
{
if ( nCol > 0 )
{
// Get Previous Column Width in order to move the next display item
GetColumn(nCol-1, &lvcprev) ;
lpDrawItemStruct->rcItem.left += lvcprev.cx ;
lpDrawItemStruct->rcItem.right += lpDrawItemStruct->rcItem.left;
} CRect rcItem;
if (!GetSubItemRect(lpDrawItemStruct->itemID,nCol,LVIR_LABEL,rcItem))
continue; ::ZeroMemory(&lvi, sizeof(lvi));
lvi.iItem = lpDrawItemStruct->itemID;
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.iSubItem = nCol;
lvi.pszText = lpBuffer;
lvi.cchTextMax = sizeof(lpBuffer);
VERIFY(GetItem(&lvi));
CRect rcTemp;
rcTemp = rcItem; if (nCol==0)
{
rcTemp.left -=2;
} if ( lpDrawItemStruct->itemState & ODS_SELECTED )
{
pDC->FillSolidRect(&rcTemp, GetSysColor(COLOR_HIGHLIGHT)) ;
pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)) ;
}
else
{
COLORREF color;
color = GetBkColor();
pDC->FillSolidRect(rcTemp,color); if (FindColColor(nCol,color))
{
pDC->FillSolidRect(rcTemp,color);
}
if (FindItemColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->FillSolidRect(rcTemp,color);
}
//pDC->SetTextColor(m_color);
} pDC->SelectObject(GetStockObject(DEFAULT_GUI_FONT)); UINT uFormat = DT_CENTER ;
if (m_Header.m_Format[nCol]=='0')
{
uFormat = DT_LEFT;
}
else if (m_Header.m_Format[nCol]=='1')
{
uFormat = DT_CENTER;
}
else if (m_Header.m_Format[nCol]=='2')
{
uFormat = DT_RIGHT;
}
TEXTMETRIC metric;
pDC->GetTextMetrics(&metric);
int ofst;
ofst = rcItem.Height() - metric.tmHeight;
rcItem.OffsetRect(0,ofst/2);
pDC->SetTextColor(m_color);
COLORREF color;
if (FindColTextColor(nCol,color))
{
pDC->SetTextColor(color);
}
if (FindItemTextColor(nCol,lpDrawItemStruct->itemID,color))
{
pDC->SetTextColor(color);
}
CFont nFont ,* nOldFont;
nFont.CreateFont(m_fontHeight,m_fontWith,0,0,0,FALSE,FALSE,0,0,0,0,0,0,_TEXT("宋体"));//创建字体
nOldFont = pDC->SelectObject(&nFont);
DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&rcItem, uFormat) ; pDC->SelectStockObject(SYSTEM_FONT) ;
}}
我要设置clistctrl某一单元格的文字颜色,skin++能实现吗?
但好像我做不到这个。
把clistctrl放在另外的一个窗口中,设置为不用skin的方法,再嵌入回现在的窗口中试试。
刚搞别的东西重新生成了次,发现了