本文章由楊芹勍原創,如需轉摘請註明出處。謝謝!
在Symbian OS中繪製圖形減少閃爍的方法有兩種:
- 使用雙緩衝進行圖形的繪製(點擊這裡進入相關文章)
- 使用CDirectScreenAccess類對螢幕進行直接繪製。
CDirectScreenAccess類在SDK種的解釋如下:
Direct screen access is a way of drawing to the screen without using the window server. As this avoids client-server communication, it is much faster, and may be useful for games and video. Note that some interaction with the window server is needed in order to prevent the application from drawing over other application's data.
此外,使用CDirectScreenAccess還可以截獲系統的通知訊息(如菜單彈出、電話撥入、資訊收到等)的對話方塊彈出事件,從而避免不必要的重新整理工作。
一、CDirectScreenAccess的簡單使用
CDirectScreenAccess使用起來非常簡單,下面的幾格步驟將介紹CDirectScreenAccess的使用方法:
- 在Carbide C++中使用嚮導產生GUI應用程式
- 在View類中建立成員變數CDirectScreenAccess* iDSA;
- 在View類中建立私人方法void DrawGraphics();代碼如下:
void CTestDirectDrawAppView::DrawGraphics()
{
CFbsBitGc* gc = iDSA->Gc();
TRgb colorRed= AKN_LAF_COLOR(35);
gc->SetPenColor(colorRed);
gc->DrawRect(TRect(0, 0, 100, 100));
iDSA->ScreenDevice()->Update();
}
- 在View類的ConstructL方法裡加入以下代碼:
CEikonEnv* env = CEikonEnv::Static();
iDSA = CDirectScreenAccess::NewL(env->WsSession(), *(env->ScreenDevice()), this->Window(), *this);
iDSA->StartL();
DrawGraphics();
- 在View類中建立以下兩個私人方法:
void Restart(RDirectScreenAccess::TTerminationReasons aReason);
void AbortNow(RDirectScreenAccess::TTerminationReasons aReason);
實現如下:
void CTestDirectDrawAppView::Restart(RDirectScreenAccess::TTerminationReasons aReason)
{
iDSA->StartL();
DrawGraphics();
}
void CTestDirectDrawAppView::AbortNow(RDirectScreenAccess::TTerminationReasons aReason)
{
iDSA->Cancel();
}
點擊此處下載原始碼
二、分析實現過程
1、普通的繪製過程
2、當有系統對話方塊通知時的繪製過程