The question is - why the code below doesn't display window immediately if I change EnableReceiptOfFocus(EFalse) to EnableReceiptOfFocus(ETrue). I get 3-4s of delay when starting or switching to such application. Yes, that's the code from Forum Nokia Wiki!
Everything works just the way it should except there is this super strange delay. Any clue?Code:#include <e32base.h> #include <w32std.h> // ws32.lib #include <coedef.h> class CCustomGraphics : public CActive { public: static CCustomGraphics* NewL(); void CustomDraw( TRect& aRect ); virtual ~CCustomGraphics(); protected: CCustomGraphics(); void ConstructL(); // from CActive void DoCancel(); void RunL(); protected: RWsSession iWsSession; CWsScreenDevice* iScreenDevice; RWindowGroup iWindowGroup; RWindow* iWindow; CWindowGc* iWindowGc; }; CCustomGraphics::CCustomGraphics() : CActive( CActive::EPriorityLow ) { CActiveScheduler::Add( this ); } CCustomGraphics* CCustomGraphics::NewL() { CCustomGraphics* self = new (ELeave) CCustomGraphics; CleanupStack::PushL( self ); self->ConstructL(); CleanupStack::Pop(); // self; return self; } void CCustomGraphics::ConstructL() { // Connect to window server session User::LeaveIfError( iWsSession.Connect() ); // Set client priority permanently to current level. See documentation on // RWsSession for more information iWsSession.ComputeMode( RWsSession::EPriorityControlDisabled ); iScreenDevice = new (ELeave) CWsScreenDevice( iWsSession ); User::LeaveIfError( iScreenDevice->Construct() ); iScreenDevice->SetScreenModeEnforcement( ESizeEnforcementNone ); iWindowGroup = RWindowGroup( iWsSession ); User::LeaveIfError( iWindowGroup.Construct( (TUint32)this, ETrue ) ); // This window group cannot receive keyboard focus iWindowGroup.EnableReceiptOfFocus( EFalse ); // Window group will always be on top iWindowGroup.SetOrdinalPosition( 0, ECoeWinPriorityAlwaysAtFront+1 ); // Create graphics context for the screen device User::LeaveIfError(iScreenDevice->CreateContext( iWindowGc ) ); // Finally, create a window, set its properties, and display it iWindow = new (ELeave) RWindow( iWsSession ); User::LeaveIfError(iWindow->Construct( iWindowGroup, (TUint32)iWindow ) ); iWindow->SetExtent( TPoint( 10, 10 ), TSize( 100, 100 ) ); iWindow->SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront+1 ); iWindow->SetCornerType( EWindowCorner5 ); iWindow->SetNonFading( ETrue ); iWindow->SetVisible( ETrue ); iWindow->Activate(); // Start waiting for redraw events iWsSession.RedrawReady( &iStatus ); SetActive(); } CCustomGraphics::~CCustomGraphics() { Cancel(); iWindow->Close(); delete iWindow; iWindowGroup.Close(); delete iWindowGc; delete iScreenDevice; iWsSession.Close(); } void CCustomGraphics::RunL() { if( iStatus == KErrNone ) { TWsRedrawEvent event; iWsSession.GetRedraw( event ); // Handle of the window which is the target of redraw event // Can be used for ID purposes if multiple windows are used RWindow* window = ( RWindow* )( event.Handle() ); // Rectangle that needs to be redrawn TRect eventRect = event.Rect(); CustomDraw( eventRect ); iWsSession.RedrawReady( &iStatus ); SetActive(); } } void CCustomGraphics::DoCancel() { iWsSession.RedrawReadyCancel(); } void CCustomGraphics::CustomDraw( TRect& /*aRect*/ ) { iWindowGc->Activate( *iWindow ); iWindow->BeginRedraw(); iWindowGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); iWindowGc->SetBrushColor( TRgb( 255, 0, 0 ) ); iWindowGc->Clear(); iWindow->EndRedraw(); iWindowGc->Deactivate(); iWsSession.Flush(); }



