CCheckListBox 如何改变checkbox里字体的颜色呢??????
时间:2011-11-25
来源:互联网
作者: wojiuguowei 发布时间: 2011-11-25
作者: VisualEleven 发布时间: 2011-11-25
作者: huadao 发布时间: 2011-11-25
DrawCheckbox(int nItem, int nSubItem, CDC *pDC, COLORREF crText, COLORREF crBkgnd, CRect& rect, XLISTCTRLDATA *pXLCD) { ASSERT(pDC); ASSERT(pXLCD); if (rect.IsRectEmpty()) { return; } GetDrawColors(nItem, nSubItem, crText, crBkgnd); pDC->FillSolidRect(&rect, crBkgnd); CRect chkboxrect; chkboxrect = rect; chkboxrect.bottom -= 1; chkboxrect.left += 9; // line up checkbox with header checkbox chkboxrect.right = chkboxrect.left + chkboxrect.Height(); // width = height CString str; str = GetItemText(nItem, nSubItem); if (str.IsEmpty()) { // center the checkbox chkboxrect.left = rect.left + rect.Width()/2 - chkboxrect.Height()/2 - 1; chkboxrect.right = chkboxrect.left + chkboxrect.Height(); } // fill rect around checkbox with white pDC->FillSolidRect(&chkboxrect, m_crWindow); // draw border CBrush brush(RGB(51,102,153)); pDC->FrameRect(&chkboxrect, &brush); if (pXLCD[nSubItem].nCheckedState == 1) { CPen *pOldPen = NULL; CPen graypen(PS_SOLID, 1, m_crGrayText); CPen blackpen(PS_SOLID, 1, RGB(51,153,51)); if (pXLCD[0].bEnabled) pOldPen = pDC->SelectObject(&blackpen); else pOldPen = pDC->SelectObject(&graypen); // draw the checkmark int x = chkboxrect.left + 9; ASSERT(x < chkboxrect.right); int y = chkboxrect.top + 3; int i; for (i = 0; i < 4; i++) { pDC->MoveTo(x, y); pDC->LineTo(x, y+3); x--; y++; } for (i = 0; i < 3; i++) { pDC->MoveTo(x, y); pDC->LineTo(x, y+3); x--; y--; } if (pOldPen) pDC->SelectObject(pOldPen); } if (!str.IsEmpty()) { pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(crText); pDC->SetBkColor(crBkgnd); CRect textrect; textrect = rect; textrect.left = chkboxrect.right + 4; UINT nFormat = DT_LEFT | DT_VCENTER | DT_SINGLELINE; //+++ if (m_bUseEllipsis) nFormat |= DT_END_ELLIPSIS; pDC->DrawText(str, &textrect, nFormat); } }
作者: shen_wei 发布时间: 2011-11-25
颜色自己改改
C/C++ code
void CDlg1Dlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your message handler code here and/or call default if(nIDCtl == m_CheckListBox.GetDlgCtrlID()) { CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); if (((LONG)(lpDrawItemStruct->itemID) >= 0) && (lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))) { int cyItem = m_CheckListBox.GetItemHeight(lpDrawItemStruct->itemID); BOOL fDisabled = !IsWindowEnabled() || !m_CheckListBox.IsEnabled(lpDrawItemStruct->itemID); COLORREF newTextColor = fDisabled ? RGB(0x80, 0x80, 0x80) : GetSysColor(COLOR_WINDOWTEXT); // light gray COLORREF oldTextColor = pDC->SetTextColor(newTextColor); COLORREF newBkColor = GetSysColor(COLOR_WINDOW); COLORREF oldBkColor = pDC->SetBkColor(newBkColor); if (newTextColor == newBkColor) newTextColor = RGB(0xC0, 0xC0, 0xC0); // dark gray if (!fDisabled && ((lpDrawItemStruct->itemState & ODS_SELECTED) != 0)) { pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT)); pDC->SetBkColor(GetSysColor(COLOR_HIGHLIGHT)); } int m_cyText = 20; TEXTMETRIC txtMetric; GetTextMetrics(pDC->GetSafeHdc(), &txtMetric); m_cyText = txtMetric.tmHeight; //if (m_cyText == 0) // VERIFY(cyItem >= CalcMinimumItemHeight()); CString strText; m_CheckListBox.GetText(lpDrawItemStruct->itemID, strText); pDC->ExtTextOut(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top + max(0, (cyItem - m_cyText) / 2), ETO_OPAQUE, &(lpDrawItemStruct->rcItem), strText, strText.GetLength(), NULL); pDC->SetTextColor(oldTextColor); pDC->SetBkColor(oldBkColor); } if ((lpDrawItemStruct->itemAction & ODA_FOCUS) != 0) pDC->DrawFocusRect(&(lpDrawItemStruct->rcItem)); return; } CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct); }
作者: zgl7903 发布时间: 2011-11-25
作者: wojiuguowei 发布时间: 2011-11-26
作者: wojiuguowei 发布时间: 2011-11-26
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28