Friday, 29 May 2009

因為被折磨吧

工作時搜尋有關 CWsBitmap 的網頁,在其中一個網頁見到這樣的 Pop up(http://tech.ddvip.com/2008-12/122844828397613.html)。

為什麼要折磨人呢?因為正被 programing 折磨吧?

再看看它的代碼,有 bug 的!
/**
* 初始化双缓冲区
*/
void CTestDoubleBufferAppView::InitDoubleBufferL()
{
  iBufBmp = new(ELeave)CWsBitmap(CEikonEnv::Static()->WsSession());
  CleanupStack::PushL(iBufBmp);
  User::LeaveIfError(iBufBmp->Create(Rect().Size(), CEikonEnv::Static()->ScreenDevice()->DisplayMode()));
  iBufDevice = CFbsBitmapDevice::NewL(iBufBmp);
  CleanupStack::PushL(iBufDevice);
  User::LeaveIfError(iBufDevice->CreateBitmapContext(iBufGc));
  CleanupStack::Pop(2); // iDevice, iBufBmp
}
/**
* 测试在缓冲区上绘制
*/
void CTestDoubleBufferAppView::DoTestDraw()
{
  iBufGc->Clear(Rect());
  // 在buffer里画方块,而不是在屏幕上
  for (int i=0; i<100; i+=2){
    DrawRect(TRect(TPoint(i, i), TSize(50, 50)));
  }
}
/**
* View的重绘事件
*/
void CTestDoubleBufferAppView::Draw(const TRect& /*aRect*/) const
{
  // 以下代码忽略
  //  // Get the standard graphics context
  //  CWindowGc& gc = SystemGc();
  //
  //  // Gets the control's extent
  //  TRect drawRect(Rect());
  //
  //  // Clears the screen
  //  gc.Clear(drawRect);
  SystemGc().BitBlt(TPoint(0, 0), iBufBmp);
}

No comments: