文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WTL-双缓冲(double buffer)绘图

WTL-双缓冲(double buffer)绘图

时间:2011-01-12  来源:wudong

下面创建了一个普通的WTL窗口类,在窗口的客户区中有大量的绘图工作,使用CDoubleBufferImpl类来消除绘图时的闪烁现象:

const COLORREF WHITE_COLOR = RGB(255,255,255);
const COLORREF BLUE_COLOR = RGB(0,0,255);
class CMainWindow :
     public CWindowImpl<CMainWindow,CWindow,CSimpleWinTraits>,
     public CDoubleBufferImpl<CMainWindow>
{
public:
     typedef CMainWindow _thisClass;
     typedef CDoubleBufferImpl<_thisClass> _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<count; i++)
             {
                     height = (int)((double)rand()*rc.Height())/RAND_MAX;
                     dc.Rectangle(x,rc.Height(),x+width,rc.Height()-height);
                     x += width;
             }
             dc.SelectPen(hOldPen);
     }
  /*
     void DoPaint(CDCHandle dc)
     {
             CRect rc;
             GetClientRect(&rc);
             int width = rc.Width(), height = rc.Height();
          //use GDI+ to draw in the client area
             Graphics g(dc.m_hDC);
             SolidBrush whiteBrush(Color(255,255,255));
             g.FillRectangle(&whiteBrush,0,0,width,height);
          Pen bluePen(Color(0,0,255));
             const int dx = 5;
             int count = width/dx;
             int x = 0, y = 0, h = 0;
             for (int i=0;i<count;i++)
             {
                     h = ((double)rand()*height)/RAND_MAX;
                     g.DrawRectangle(&bluePen,x,y,dx,h);
                     x += dx;
             }
     }
     */
private:
     CPen m_RectPen;
};
相关阅读 更多 +
排行榜 更多 +
后室双重现实游戏下载

后室双重现实游戏下载

冒险解谜 下载
魔音少女模拟器下载最新版

魔音少女模拟器下载最新版

模拟经营 下载
雷曼大冒险官方版下载

雷曼大冒险官方版下载

冒险解谜 下载