当前位置: 编程技术>c/c++/嵌入式
基于WTL 双缓冲(double buffer)绘图的分析详解
来源: 互联网 发布时间:2014-10-14
本文导语: WTL中有两个Mix-in类: CDoubleBufferImpl和CDoubleBufferWindowImpl,用于创建双缓冲绘图窗口,用法非常简单。下面创建了一个普通的WTL窗口类,在窗口的客户区中有大量的绘图工作,使用CDoubleBufferImpl类来消除绘图时的闪烁现象: 代码如...
WTL中有两个Mix-in类: CDoubleBufferImpl和CDoubleBufferWindowImpl,用于创建双缓冲绘图窗口,用法非常简单。
下面创建了一个普通的WTL窗口类,在窗口的客户区中有大量的绘图工作,使用CDoubleBufferImpl类来消除绘图时的闪烁现象:
const COLORREF WHITE_COLOR = RGB(255,255,255);
const COLORREF BLUE_COLOR = RGB(0,0,255);
class CMainWindow :
public CWindowImpl,
public CDoubleBufferImpl
{
public:
typedef CMainWindow _thisClass;
typedef CDoubleBufferImpl _baseDblBufImpl;
BEGIN_MSG_MAP(CMainWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(_baseDblBufImpl)
END_MSG_MAP()
int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_RectPen.CreatePen(PS_SOLID,1,BLUE_COLOR);
return 0;
}
void OnDestroy()
{
PostQuitMessage(0);
}
void OnPaint(CDCHandle)
{
CPaintDC dc(m_hWnd);
DoPaint(dc.m_hDC);
}
void DoPaint(CDCHandle dc)
{
CRect rc;
GetClientRect(&rc);
dc.FillRect(&rc,WHITE_COLOR);
HPEN hOldPen = dc.SelectPen(m_RectPen);
const int width = 5;
int x = 0;
int count = rc.Width()/width;
int height = 0;
for (int i=0; i
下面创建了一个普通的WTL窗口类,在窗口的客户区中有大量的绘图工作,使用CDoubleBufferImpl类来消除绘图时的闪烁现象:
代码如下:
const COLORREF WHITE_COLOR = RGB(255,255,255);
const COLORREF BLUE_COLOR = RGB(0,0,255);
class CMainWindow :
public CWindowImpl,
public CDoubleBufferImpl
{
public:
typedef CMainWindow _thisClass;
typedef CDoubleBufferImpl _baseDblBufImpl;
BEGIN_MSG_MAP(CMainWindow)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
CHAIN_MSG_MAP(_baseDblBufImpl)
END_MSG_MAP()
int OnCreate(LPCREATESTRUCT lpCreateStruct)
{
m_RectPen.CreatePen(PS_SOLID,1,BLUE_COLOR);
return 0;
}
void OnDestroy()
{
PostQuitMessage(0);
}
void OnPaint(CDCHandle)
{
CPaintDC dc(m_hWnd);
DoPaint(dc.m_hDC);
}
void DoPaint(CDCHandle dc)
{
CRect rc;
GetClientRect(&rc);
dc.FillRect(&rc,WHITE_COLOR);
HPEN hOldPen = dc.SelectPen(m_RectPen);
const int width = 5;
int x = 0;
int count = rc.Width()/width;
int height = 0;
for (int i=0; i