我的对话框窗口上有自绘的ListBox,别的窗口在他上面移动时ListBox会闪烁得很厉害,但对话框自己移动时不闪烁,请问这是怎么回事?

hxliurui 2005-10-31 09:19:57
我的对话框窗口上有自绘的ListBox,别的窗口在他上面移动时ListBox会闪烁得很厉害,但对话框自己移动时不闪烁,请问这是怎么回事?
...全文
278 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hxliurui 2005-11-09
  • 打赏
  • 举报
回复
终于好了,不过是要把对话框和控件都加上WS_CLIPCHILDREN(控件不加WS_CLIPCHILDREN也可以)。而且对话框改变窗口风格不能在PreCreateWindow()里加,我是在OnInitDialog()里加ModifyStyle(0, WS_CLIPCHILDREN)。
psbeond 2005-11-08
  • 打赏
  • 举报
回复
使用我上面说的方法不可能不行的。如果不行,说明你没处理好,到www.iuishop.com的下载页中去下载一个TreeListCtrl,里面有源代码,你参考一下。
hxliurui 2005-11-07
  • 打赏
  • 举报
回复
有好心人吗?
hxliurui 2005-11-04
  • 打赏
  • 举报
回复
我用上面的方法都试过了,还是不行。
我的界面是参考skinsyse做的http://www.codeproject.com/dialog/skinsyse.asp,在skinsyse的画面上拖动也会闪烁,困惑啊
hxliurui 2005-11-01
  • 打赏
  • 举报
回复
为什么移动的时候不闪烁?也是调了OnPaint的啊
psbeond 2005-10-31
  • 打赏
  • 举报
回复
对话框和控件都去掉WS_CLIPCHILDREN和WS_CLIPSIBLINGS风格,把listbox的erase background消息return TRUE;在WM_PAINT消息中, DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0),在把memDC的内容画到dc上.
goodboyws 2005-10-31
  • 打赏
  • 举报
回复
假设你是在OnPaint画的
int CMyList::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CRect rc;
GetClientRect(rc);
CDC* pDC = GetDC();
m_MemDC.CreateCompatibleDC(pDC);
m_Bitmap.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
m_MemDC.SelectObject(&m_Bitmap);
ReleaseDC(pDC);
return CListBox::OnCreate(lpCreateStruct);
}
void CMyList::OnPaint()
{

CRect rcClient;
GetClientRect(&rcClient);

CPaintDC dc(this);
if (m_bBitmap)
{
DrawList(&m_MemDC);
m_bBitmap = FALSE;
}

dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(),
&m_MemDC, 0, 0, SRCCOPY);
}
需要主动更新的时候将m_bBitmap置为TRUE;
会思考的草 2005-10-31
  • 打赏
  • 举报
回复
试试在创建窗口的时候去掉WS_CLIPSIBLINGS属性。
hxliurui 2005-10-31
  • 打赏
  • 举报
回复
To goodboyws(深夜不眠者)

我没用DrawItem,把下面这段加上还是要闪。

BOOL CBitmapList::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default

return FALSE;
}
hxliurui 2005-10-31
  • 打赏
  • 举报
回复
To happyparrot(快乐鹦鹉)
void CBitmapList::OnPaint()
{
CPaintDC dc(this); // device context for painting

CRect Rect;
GetClientRect(&Rect);

int Width = Rect.Width();
int Height = Rect.Height();

CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
CBitmap MemBmp;
MemBmp.CreateCompatibleBitmap(&dc,Width,Height);

CBitmap *pOldMemBmp = MemDC.SelectObject(&MemBmp);

//我的对话框是不规则的一个BMP,m_Back是需要显示listbox的背景
CDC MemDC2;
MemDC2.CreateCompatibleDC(&dc);
CBitmap *pOldbmp = MemDC2.SelectObject(&m_Back);
MemDC.BitBlt(0,0,Width,Height,&MemDC2,0,0,SRCCOPY);
MemDC2.SelectObject(pOldbmp);


Rect.top = 0;
Rect.left = 0;
Rect.bottom = Rect.top + GetItemHeight(0);
Rect.right = Width;

int size = GetCount();
for (int i = GetTopIndex(); i < size && Rect.top <= Height;++i)
{
DrawItem(MemDC,i,Rect,GetSel(i));
Rect.OffsetRect(0,GetItemHeight(i));
}

dc.BitBlt(0,0,Width,Height,&MemDC,0,0,SRCCOPY);
m_SkinVerticleScrollbar.UpdateThumbPosition();

MemDC.SelectObject(pOldMemBmp);
}


void CBitmapList::DrawItem(CDC &Dc,int nIndex,CRect &Rect,BOOL Selected)
{
STRUCT_LBDATA* lpLBData = NULL;
CString strText;

if (nIndex == LB_ERR || nIndex >= GetCount())
return;


lpLBData = (STRUCT_LBDATA *)CListBox::GetItemDataPtr(nIndex);
if (lpLBData == NULL || lpLBData == (LPVOID)-1L) return;

CRect rcItem = Rect;
CRect rcIcon = Rect;
CRect rcText = Rect;
CRect rcCenteredText = Rect;

//在list item上画icon
// Calculate rcIcon
if (m_pImageList)
{
rcIcon.left = rcIcon.left - CX_BORDER*3;
rcIcon.right = rcIcon.left + m_szImage.cx + CX_BORDER;
//rcIcon.bottom = rcIcon.top + m_szImage.cy + CY_BORDER*2;
rcIcon.top = rcIcon.top - 5;
rcIcon.bottom = rcIcon.top + m_szImage.cy;
} // if
else rcIcon.SetRect(0, 0, 0, 0);

// Calculate rcText
if (lpLBData->nImage != -1)
{
rcText.left = rcIcon.right;
rcText.top = rcIcon.top + 8;
}
else
{
rcText.left = CX_BORDER;
rcText.top = rcIcon.top + 8;
}

// Draw the icon (if any)
if (m_pImageList)
OnDrawIcon(nIndex, &Dc, &Rect, &rcIcon,
lpLBData->nImage, FALSE, Selected);


CRect TheRect = Rect;
Dc.SetBkMode(TRANSPARENT);

CDC memdc;
memdc.CreateCompatibleDC(&Dc);

CFont *pFont = GetFont();
CFont *oldFont = Dc.SelectObject(pFont);
CBitmap *oldbmp = memdc.SelectObject(&m_Bmp);
Dc.BitBlt(TheRect.left,TheRect.top,TheRect.Width(),TheRect.Height(),&memdc,TheRect.left,TheRect.top,SRCCOPY);
CString Text;
GetText(nIndex,Text);

if (IsWindowEnabled())
{
if (Selected)
{
Dc.SetTextColor(m_SelColor);
}
else
{
Dc.SetTextColor(m_Color);
}
}
else
{
Dc.SetTextColor(RGB(140,140,140));
}
//Dc.DrawText(Text,TheRect,DT_LEFT|DT_EXPANDTABS|DT_NOPREFIX);
Dc.DrawText(Text,rcText,DT_LEFT);
Dc.SelectObject(oldFont);
memdc.SelectObject(oldbmp);
}
goodboyws 2005-10-31
  • 打赏
  • 举报
回复
映射WM_ERASEBKGND
BOOL CMyListBox::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return FALSE;
}
DrawItem里用双缓冲
快乐鹦鹉 2005-10-31
  • 打赏
  • 举报
回复
如何自绘的?
菜牛 2005-10-31
  • 打赏
  • 举报
回复
我没用DrawItem


+++++++++++++++++++++++++++++++++++++++++++++++
那何必自绘ListBox,不如直接从CWnd继承算了。

15,979

社区成员

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

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