程序启动时闪屏功能的实现

为了让程序花哨一点,最近想实现一个程序启动时有一个全屏的界面,中间有一幅图片的功能,查找了一些资料,首先是要让全屏显示,查到好几种方法,选用了其中最简单的一种:AppUi()->ApplicationRect(),这样可实现,但是在显示的时候状态栏上边的信号指示和电量指示器还都存在,影响美观,反复测试发现下面方法可行:

在UI里把状态栏替换为空,在闪屏时间到时再恢复到默认状态栏即可,主要代码如下:

SplashWindowView.h

  1. /*
  2. ============================================================================
  3.  Name        : CSplashWindowView from SplashWindowView.h
  4.  Author      : 
  5.  Version     :
  6.  Copyright   : Your copyright notice
  7.  Description : CSplashWindowView declaration
  8. ============================================================================
  9. */
  10. #ifndef SPLASHWINDOWVIEW_H
  11. #define SPLASHWINDOWVIEW_H
  12. // INCLUDES
  13. #include <aknview.h>
  14. // CONSTANTS
  15. // FORWARD DECLARATIONS
  16. class CSplashWindowContainer;
  17. // CLASS DECLARATION
  18. /**
  19. *  CSplashWindowView view class.
  20. */
  21. class CSplashWindowView : public CAknView,CActive
  22.     {
  23.     public// Constructors and destructor
  24.         /**
  25.         * EPOC default constructor.
  26.         */
  27.         void ConstructL();
  28.         /**
  29.         * Destructor.
  30.         */
  31.         ~CSplashWindowView();
  32.         CSplashWindowView();
  33.     public// Functions from base classes
  34.         
  35.         /**
  36.         * From CAknView returns Uid of View
  37.         * @return TUid uid of the view
  38.         */
  39.         TUid Id() const;
  40.         /**
  41.         * From MEikMenuObserver delegate commands from the menu
  42.         * @param aCommand a command emitted by the menu 
  43.         * @return void
  44.         */
  45.         void HandleCommandL(TInt aCommand);
  46.         /**
  47.         * From CAknView reaction if size change
  48.         * @return void
  49.         */
  50.         void HandleClientRectChange();
  51.         
  52.     private:
  53.         void RunL();
  54.         void DoCancel();
  55.         TInt RunError(TInt aError);
  56.     private:
  57.         /**
  58.         * From CAknView activate the view
  59.         * @param aPrevViewId 
  60.         * @param aCustomMessageId 
  61.         * @param aCustomMessage 
  62.         * @return void
  63.         */
  64.         void DoActivateL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,
  65.             const TDesC8& aCustomMessage);
  66.         /**
  67.         * From CAknView deactivate the view (free resources)
  68.         * @return void
  69.         */
  70.         void DoDeactivate();
  71.     private// Data
  72.         CSplashWindowContainer* iContainer;
  73.         RTimer iTimer;
  74.     };
  75. #endif
  76. // End of File

 

SplashWindowView.cpp

  1. /*
  2. ============================================================================
  3.  Name        : CSplashWindowView from SplashWindowView.h
  4.  Author      : 
  5.  Version     :
  6.  Copyright   : Your copyright notice
  7.  Description : CSplashWindowView implementation
  8. ============================================================================
  9. */
  10. // INCLUDE FILES
  11. #include  <aknviewappui.h>
  12. #include  <avkon.hrh>
  13. #include  "SplashWindowView.h"
  14. #include  "SplashWindowContainer.h"
  15. #include <eikspane.h>
  16. #include <avkon.rsg>
  17. // ================= MEMBER FUNCTIONS =======================
  18. // ---------------------------------------------------------
  19. // CSplashWindowView::ConstructL(const TRect& aRect)
  20. // EPOC two-phased constructor
  21. // ---------------------------------------------------------
  22. //
  23. void CSplashWindowView::ConstructL()
  24.     {
  25.     BaseConstructL( R_SMSCHEAT_SPLASHWINDOW_VIEW );
  26.     iTimer.CreateLocal();
  27.     }
  28. CSplashWindowView::CSplashWindowView():CActive(CActive::EPriorityStandard)
  29.     {
  30.     CActiveScheduler::Add(this);
  31.     }
  32. // ---------------------------------------------------------
  33. // CSplashWindowView::~CSplashWindowView()
  34. // destructor
  35. // ---------------------------------------------------------
  36. //
  37. CSplashWindowView::~CSplashWindowView()
  38.     {
  39.     if ( iContainer )
  40.         {
  41.         AppUi()->RemoveFromViewStack( *this, iContainer );
  42.         }
  43.     delete iContainer;
  44.     
  45.     Cancel();
  46.     iTimer.Close();
  47.     }
  48. // ---------------------------------------------------------
  49. // TUid CSplashWindowView::Id()
  50. //
  51. // ---------------------------------------------------------
  52. //
  53. TUid CSplashWindowView::Id() const
  54.     {
  55.         return TUid::Uid(ESmsCheatSplashView);
  56.     }
  57. // ---------------------------------------------------------
  58. // CSplashWindowView::HandleCommandL(TInt aCommand)
  59. // takes care of view command handling
  60. // ---------------------------------------------------------
  61. //
  62. void CSplashWindowView::HandleCommandL(TInt aCommand)
  63.     {   
  64.     switch ( aCommand )
  65.         {
  66.         case EAknSoftkeyOk:
  67.             {
  68.             iEikonEnv->InfoMsg( _L("view1 ok") );
  69.             break;
  70.             }
  71.         case EAknSoftkeyBack:
  72.             {
  73.             AppUi()->HandleCommandL(EEikCmdExit);
  74.             break;
  75.             }
  76.         default:
  77.             {
  78.             AppUi()->HandleCommandL( aCommand );
  79.             break;
  80.             }
  81.         }
  82.     }
  83. // ---------------------------------------------------------
  84. // CSplashWindowView::HandleClientRectChange()
  85. // ---------------------------------------------------------
  86. //
  87. void CSplashWindowView::HandleClientRectChange()
  88.     {
  89.     if ( iContainer )
  90.         {
  91.         iContainer->SetRect( ClientRect() );
  92.         }
  93.     }
  94. // ---------------------------------------------------------
  95. // CSplashWindowView::DoActivateL(...)
  96. // 
  97. // ---------------------------------------------------------
  98. //
  99. void CSplashWindowView::DoActivateL(
  100.    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
  101.    const TDesC8& /*aCustomMessage*/)
  102.     {
  103.     if (!iContainer)
  104.         {
  105.         iContainer = new (ELeave) CSplashWindowContainer();
  106.         iContainer->SetMopParent(this);
  107.         iContainer->ConstructL( AppUi()->ApplicationRect() );
  108.         AppUi()->AddToStackL( *this, iContainer );
  109.         iTimer.After(iStatus,800000);
  110.         SetActive();    
  111.         } 
  112.    }
  113. // ---------------------------------------------------------
  114. // CSplashWindowView::DoDeactivate()
  115. // 
  116. // ---------------------------------------------------------
  117. //
  118. void CSplashWindowView::DoDeactivate()
  119.     {
  120.     if ( iContainer )
  121.         {
  122.         AppUi()->RemoveFromViewStack( *this, iContainer );
  123.         }
  124.     
  125.     delete iContainer;
  126.     iContainer = NULL;
  127.     }
  128. void CSplashWindowView::RunL()
  129.     {
  130.     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
  131.     if ( statusPane->CurrentLayoutResId()== R_AVKON_STATUS_PANE_LAYOUT_EMPTY)
  132.         {
  133.           statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
  134.         }   
  135.     AppUi()->ActivateLocalViewL(TUid::Uid(ESmsCheatMainView));
  136.     }
  137. void CSplashWindowView::DoCancel()
  138.     {
  139.     iTimer.Cancel();
  140.     }
  141. TInt CSplashWindowView::RunError(TInt aError)
  142.     {
  143.     return aError;
  144.     }
  145. // End of File

 

UI类里需要修改的:

在ConstructL()中加入

  1.     CEikStatusPane* statusPane =StatusPane();
  2.     if ( statusPane->CurrentLayoutResId()!= R_AVKON_STATUS_PANE_LAYOUT_EMPTY)
  3.         {
  4.           statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
  5.         }   

 

在CSplashWindowContainer中完成图片的绘制,我使用的SVG图片

     CFbsBitmap*     iBkImage;
     CFbsBitmap*     iBkImageMask;
     TSize iSize;

  1. void CSplashWindowContainer::ConstructL(const TRect& aRect)
  2.     {
  3.     CreateWindowL();
  4.     TFileName fullname(KIconFileName);
  5.     iSize.iHeight=88;
  6.     iSize.iWidth=88;
  7.     AknIconUtils::CreateIconL(iBkImage, iBkImageMask, fullname, EMbmSmscheat_bmpQgn_menu, EMbmSmscheat_bmpQgn_menu_mask);
  8.     AknIconUtils::SetSize(iBkImage, iSize, EAspectRatioPreserved);
  9.          
  10.     SetRect(aRect);
  11.     ActivateL();
  12.     }
  13. void CSplashWindowContainer::Draw(const TRect& aRect) const
  14.     {   
  15.     CWindowGc& gc = SystemGc();
  16.     TPoint pn;
  17.     pn.iX=aRect.Width()/2-iSize.iWidth/2;
  18.     pn.iY=aRect.Height()/2-iSize.iHeight/2;
  19.      
  20.     gc.BitBltMasked(pn,iBkImage,iSize,iBkImageMask,ETrue);
  21.     }

 

完成,图片显示的时间可设置,大小可设置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值