询问者
自绘Combobox里的item白边

问题
全部回复
-
你好,
您能否提供给我们一些实例代码,这样可以方便我们重现您的问题?
我们期待您的回信,并乐意帮助您解决您的问题
Rob Pan [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
void PngCombobox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //绘制Item背景和字符串 Graphics graphics(lpDrawItemStruct -> hDC); int curID = lpDrawItemStruct -> itemID; CRect itemTempRect( lpDrawItemStruct -> rcItem); Rect itemRect(itemTempRect.left, itemTempRect.top, itemTempRect.Width(), itemTempRect.Height()); //已选择项的Rect Rect itemBgRect(itemRect); //未选择项的Rect if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { graphics.DrawImage(_selectButtonImage, itemRect, BUTTON_CLICK * _listButtonW, 0, _listButtonW, _listButtonH, UnitPixel); } else { SolidBrush bgBrush(Color(80, 80, 80)); graphics.FillRectangle(&bgBrush, itemBgRect); graphics.DrawImage(_listImage, itemBgRect, 0, 0, _listW, _listH, UnitPixel); } //绘制Item字符串 if((curID != -1) && _DrawChars) { Gdiplus::Font myFont(L"宋体", 10.0f); PointF point( itemTempRect.left + 2.0f, itemTempRect.top + 2.0f); SolidBrush whiteBrush(Color(200,200,200)); CString itemText; GetLBText(curID,itemText); //获取当前Item字符串 wstring witemText(itemText.AllocSysString()); //转换为wstring graphics.DrawString(witemText.c_str(), -1, &myFont, point, &whiteBrush); } } void PngCombobox::OnPaint() { CPaintDC dc(this); Graphics graphics(dc.m_hDC); CRect rect; GetClientRect(&rect); graphics.DrawImage(_staticImage,Rect(0, 0, rect.Width(), rect.Height()), _staticW * _State, 0, _staticW, _staticH, UnitPixel); COMBOBOXINFO info; info.cbSize = sizeof info; GetComboBoxInfo(&info); RECT ItemRect = info.rcItem; Gdiplus::Font myFont(L"宋体", 10.0f); PointF point( ItemRect.left + 2.0f, ItemRect.top + 2.0f); SolidBrush whiteBrush(Color(200,200,200)); CString itemText; GetLBText(GetCurSel(), itemText); wstring witemText(itemText.AllocSysString()); graphics.DrawString(witemText.c_str(), -1, &myFont, point, &whiteBrush); }
我是快乐的小鱼^_^