改变CComboBox的颜色??

sms88 sms88 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我从CComboBox派生出CColorPickerCB类,然后实现以下函数
void CColorPickerCB::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dcContext;
CRect rItemRect(lpDrawItemStruct -> rcItem);
CRect rBlockRect(rItemRect);
CRect rTextRect(rBlockRect);
int iItem = lpDrawItemStruct -> itemID;
int iState = lpDrawItemStruct -> itemState;
CBrush brFrameBrush;
COLORREF crColor = 0;
COLORREF crNormal = GetSysColor(COLOR_HIGHLIGHT);
COLORREF crSelected = GetSysColor(COLOR_WINDOW);
COLORREF crText = GetSysColor(COLOR_WINDOWTEXT);
if (!dcContext.Attach(lpDrawItemStruct -> hDC)) // Attach CDC Object
return;
if (iState & ODS_SELECTED) // If Selected
{ // Set Selected Attributes
dcContext.SetTextColor(0x00AACCFF );
// dcContext.SetTextColor((0x00AACCFF & ~(crText))); // Set Inverted Text Color (With Mask)
//dcContext.SetBkColor(crSelected); // Set BG To Highlight Color
dcContext.SetBkColor(0x00AACCFF);
dcContext.FillSolidRect(&rBlockRect, crSelected); // Erase Item
}
else // If Not Selected
{ // Set Standard Attributes
dcContext.SetTextColor(crText); // Set Text Color
dcContext.SetBkColor(crNormal); // Set BG Color
dcContext.FillSolidRect(&rBlockRect, crNormal); // Erase Item
}
if (iState & ODS_FOCUS) // If Item Has The Focus
dcContext.DrawFocusRect(&rItemRect);
// TODO: Add your code to draw the specified item

}


然后在对话框中,拉入一CComboBox,且这个CComboBox关联到CColorPickerCB类型的变量m_nColor中.
为何没有改变下拉列表的颜色呢?
...全文
评论 4
收藏 已收藏
分享
返回顶部
sms88
VC/MFC 16,550 成员 421,606 内容