分割窗口里面的CListBox重绘就不显示.在线等

h25094152 2012-06-17 11:09:27
重绘的代码:
void CTabList::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);

//设置颜色
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
COLORREF crTest = RGB(255,200,10) ; //测试用

COLORREF m_clrCenter = RGB(100,50,10) ; //渐变色用 中间的颜色
COLORREF m_clrEnds = RGB(255,200,10) ; //渐变色用 2边的颜色
CRect rcItem = lpDrawItemStruct->rcItem; //下面的函数要用到,必须写.不然没有默认值;
rcItem.DeflateRect(1, 1);

//----------------------------------------------

// If this item is selected, set the background color
// and the text color to appropriate values. Also, erase
// rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));

//设置背景色 并添充
dc.SetBkColor(crTest);
dc.FillSolidRect(&lpDrawItemStruct->rcItem,
crTest);
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);


////设置渐变色分隔线 自定义下划线函数
DrawCurvLine(&dc,
CPoint(rcItem.left + 6, rcItem.bottom),
CPoint(rcItem.right - 6, rcItem.bottom),
m_clrCenter,
m_clrEnds);
}

//If this item has the focus, draw a red frame around the
//item's rect.
if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&
(lpDrawItemStruct->itemState & ODS_FOCUS))
{
CBrush br(RGB(100, 100, 150));
//设置选中的边框颜色
dc.FrameRect(&lpDrawItemStruct->rcItem, &br);
}
//----------------------------------------------
//显示图标
CImageList m_image;
m_image.Create(16, //Create(宽,高
15,
TRUE,
20, // number of initial images
20);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
m_image.Add( &bmp, RGB(255,255,255));
bmp.DeleteObject();
CPoint Pt(lpDrawItemStruct->rcItem.left+20 , lpDrawItemStruct->rcItem.top+8 );
m_image.Draw(&dc,0, Pt ,ILD_NORMAL);

//----------------------------------------------
//输出文本

GetText(lpDrawItemStruct->itemID, strText); //这样得到Text
dc.DrawText(
strText,
wcslen(strText),
&lpDrawItemStruct->rcItem,
DT_SINGLELINE|DT_VCENTER |DT_CENTER); //DT_CENTER居中


//----------------------------------------------
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
//----------------

调用的代码:
void CLeftView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
DWORD dwStyle = WS_CHILD | WS_VISIBLE | LBS_OWNERDRAWVARIABLE |
LBS_NOTIFY | LBS_HASSTRINGS;
m_TabList.Create(dwStyle,CRect(10,10,200,200), this, ID_TABLIST);
m_TabList.AddString( _T("ok1 ") );
m_TabList.AddString( _T("ok2 ") );
m_TabList.AddString( _T("气水 ") );
}

只要在建创的时候选择重绘风格LBS_OWNERDRAWVARIABLE 列表就不显示.为空白.为什么在线等.


...全文
141 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
h25094152 2012-06-17
  • 打赏
  • 举报
回复
我搞定了.原来是添错消息了 - -!
应该是添加重绘的 DrawIten 我给添加成WM_DramItem了.
h25094152 2012-06-17
  • 打赏
  • 举报
回复
谁给个QQ.帮我调一下.
h25094152 2012-06-17
  • 打赏
  • 举报
回复
我刚设成Debug了.出现 断言错误了.还在看是怎么回呈.
schlafenhamster 2012-06-17
  • 打赏
  • 举报
回复
网摘:
LBS_OWNERDRAWFIXED是使图标高度一样且只发送一次WM_MEASUREITEM,而LBS_OWNERDRAWVARIABLE是使图标高度变化且对每个图标都要发送WM_MEASUREITEM。
Eleven 2012-06-17
  • 打赏
  • 举报
回复
你Debug下调试一下进入了DrawItem中了吗?
h25094152 2012-06-17
  • 打赏
  • 举报
回复
楼主怎么解决的.我也碰到同样问题.
h25094152 2012-06-17
  • 打赏
  • 举报
回复
自己顶.我用的是VS2010.

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧