用鼠标滚轮产生的界面闪烁问题??

kikitang11 2006-04-24 11:12:22
我在ondraw中 用textout函数 输出几个数据
当鼠标滚轮滚动时,数据也相应的更新,
但我发现在数据更新的同时,界面闪烁很厉害!
怎么办啊!有什么办法解决吗?
注:在鼠标滚轮的响应函数中我对数据处理后,用invalidate来更新view~!
...全文
476 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kikitang11 2006-04-25
  • 打赏
  • 举报
回复
能给一个双缓存解决界面闪烁的例子吗?
谢谢
swordman@hotmail.com
boluoCTO 2006-04-24
  • 打赏
  • 举报
回复
把你的DC还成这个类
class CMemDC : public CDC
{
public:

//constructor sets up the memory DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);

m_pDC = pDC;
m_pOldBitmap = NULL;

#ifndef WCE_NO_PRINTING
m_bMemDC = !pDC->IsPrinting();
#else
m_bMemDC = FALSE;
#endif

if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
#ifndef _WIN32_WCE
SetWindowOrg(m_rect.left, m_rect.top);
#endif
// EFW - Bug fix - Fill background in case the user has overridden
// WM_ERASEBKGND. We end up with garbage otherwise.
// CJM - moved to fix a bug in the fix.

FillSolidRect(m_rect, (COLORREF)GetSysColor( COLOR_WINDOW ) );

}
else // Make a copy of the relevent parts of the current DC for printing
{
#if !defined(_WIN32_WCE) || ((_WIN32_WCE > 201) && !defined(WCE_NO_PRINTING))
m_bPrinting = pDC->m_bPrinting;
#endif
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}

}

// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);

//m_pDC->DrawState( CPoint( 10 ,10 ) , CSize( m_rect.right , m_rect.bottom ), &m_bitmap , DST_BITMAP | DSS_DISABLED );

//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}

// Allow usage as a pointer
CMemDC* operator->() {return this;}

// Allow usage as a pointer
operator CMemDC*() {return this;}


void DrawDisabled() {

CPen pen;

pen.CreatePen( PS_DOT , 1 , RGB( 192 , 192 , 192 ) );
SelectObject( &pen );

for( int y = 0 ; y < m_rect.bottom ; y++ ) {
MoveTo( ( ! (y % 2) ) ? 0 : 3 , y );
LineTo( m_rect.right , y );
}; //for


pen.DeleteObject();




}

CRect m_rect; // Rectangle of drawing area.

private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};
liu_tang 2006-04-24
  • 打赏
  • 举报
回复
CreateCompatibleDC建立内存DC,再用BitBlt贴图
cpio 2006-04-24
  • 打赏
  • 举报
回复
一般是通过双缓冲解决闪烁的问题

先画到内存里面

再通过Bitblt函数复制到OnDraw的pDC上
tfq2002 2006-04-24
  • 打赏
  • 举报
回复
鼠标滚轮的响应函数中头为分别加上:
SetRedraw(FALSE),SetRedraw(TRUE)

15,976

社区成员

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

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