为了让程序花哨一点,最近想实现一个程序启动时有一个全屏的界面,中间有一幅图片的功能,查找了一些资料,首先是要让全屏显示,查到好几种方法,选用了其中最简单的一种:AppUi()->ApplicationRect(),这样可实现,但是在显示的时候状态栏上边的信号指示和电量指示器还都存在,影响美观,反复测试发现下面方法可行:
在UI里把状态栏替换为空,在闪屏时间到时再恢复到默认状态栏即可,主要代码如下:
SplashWindowView.h
- /*
- ============================================================================
- Name : CSplashWindowView from SplashWindowView.h
- Author :
- Version :
- Copyright : Your copyright notice
- Description : CSplashWindowView declaration
- ============================================================================
- */
- #ifndef SPLASHWINDOWVIEW_H
- #define SPLASHWINDOWVIEW_H
- // INCLUDES
- #include <aknview.h>
- // CONSTANTS
- // FORWARD DECLARATIONS
- class CSplashWindowContainer;
- // CLASS DECLARATION
- /**
- * CSplashWindowView view class.
- *
- */
- class CSplashWindowView : public CAknView,CActive
- {
- public: // Constructors and destructor
- /**
- * EPOC default constructor.
- */
- void ConstructL();
- /**
- * Destructor.
- */
- ~CSplashWindowView();
- CSplashWindowView();
- public: // Functions from base classes
- /**
- * From CAknView returns Uid of View
- * @return TUid uid of the view
- */
- TUid Id() const;
- /**
- * From MEikMenuObserver delegate commands from the menu
- * @param aCommand a command emitted by the menu
- * @return void
- */
- void HandleCommandL(TInt aCommand);
- /**
- * From CAknView reaction if size change
- * @return void
- */
- void HandleClientRectChange();
- private:
- void RunL();
- void DoCancel();
- TInt RunError(TInt aError);
- private:
- /**
- * From CAknView activate the view
- * @param aPrevViewId
- * @param aCustomMessageId
- * @param aCustomMessage
- * @return void
- */
- void DoActivateL(const TVwsViewId& aPrevViewId,TUid aCustomMessageId,
- const TDesC8& aCustomMessage);
- /**
- * From CAknView deactivate the view (free resources)
- * @return void
- */
- void DoDeactivate();
- private: // Data
- CSplashWindowContainer* iContainer;
- RTimer iTimer;
- };
- #endif
- // End of File
SplashWindowView.cpp
- /*
- ============================================================================
- Name : CSplashWindowView from SplashWindowView.h
- Author :
- Version :
- Copyright : Your copyright notice
- Description : CSplashWindowView implementation
- ============================================================================
- */
- // INCLUDE FILES
- #include <aknviewappui.h>
- #include <avkon.hrh>
- #include "SplashWindowView.h"
- #include "SplashWindowContainer.h"
- #include <eikspane.h>
- #include <avkon.rsg>
- // ================= MEMBER FUNCTIONS =======================
- // ---------------------------------------------------------
- // CSplashWindowView::ConstructL(const TRect& aRect)
- // EPOC two-phased constructor
- // ---------------------------------------------------------
- //
- void CSplashWindowView::ConstructL()
- {
- BaseConstructL( R_SMSCHEAT_SPLASHWINDOW_VIEW );
- iTimer.CreateLocal();
- }
- CSplashWindowView::CSplashWindowView():CActive(CActive::EPriorityStandard)
- {
- CActiveScheduler::Add(this);
- }
- // ---------------------------------------------------------
- // CSplashWindowView::~CSplashWindowView()
- // destructor
- // ---------------------------------------------------------
- //
- CSplashWindowView::~CSplashWindowView()
- {
- if ( iContainer )
- {
- AppUi()->RemoveFromViewStack( *this, iContainer );
- }
- delete iContainer;
- Cancel();
- iTimer.Close();
- }
- // ---------------------------------------------------------
- // TUid CSplashWindowView::Id()
- //
- // ---------------------------------------------------------
- //
- TUid CSplashWindowView::Id() const
- {
- return TUid::Uid(ESmsCheatSplashView);
- }
- // ---------------------------------------------------------
- // CSplashWindowView::HandleCommandL(TInt aCommand)
- // takes care of view command handling
- // ---------------------------------------------------------
- //
- void CSplashWindowView::HandleCommandL(TInt aCommand)
- {
- switch ( aCommand )
- {
- case EAknSoftkeyOk:
- {
- iEikonEnv->InfoMsg( _L("view1 ok") );
- break;
- }
- case EAknSoftkeyBack:
- {
- AppUi()->HandleCommandL(EEikCmdExit);
- break;
- }
- default:
- {
- AppUi()->HandleCommandL( aCommand );
- break;
- }
- }
- }
- // ---------------------------------------------------------
- // CSplashWindowView::HandleClientRectChange()
- // ---------------------------------------------------------
- //
- void CSplashWindowView::HandleClientRectChange()
- {
- if ( iContainer )
- {
- iContainer->SetRect( ClientRect() );
- }
- }
- // ---------------------------------------------------------
- // CSplashWindowView::DoActivateL(...)
- //
- // ---------------------------------------------------------
- //
- void CSplashWindowView::DoActivateL(
- const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
- const TDesC8& /*aCustomMessage*/)
- {
- if (!iContainer)
- {
- iContainer = new (ELeave) CSplashWindowContainer();
- iContainer->SetMopParent(this);
- iContainer->ConstructL( AppUi()->ApplicationRect() );
- AppUi()->AddToStackL( *this, iContainer );
- iTimer.After(iStatus,800000);
- SetActive();
- }
- }
- // ---------------------------------------------------------
- // CSplashWindowView::DoDeactivate()
- //
- // ---------------------------------------------------------
- //
- void CSplashWindowView::DoDeactivate()
- {
- if ( iContainer )
- {
- AppUi()->RemoveFromViewStack( *this, iContainer );
- }
- delete iContainer;
- iContainer = NULL;
- }
- void CSplashWindowView::RunL()
- {
- CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
- if ( statusPane->CurrentLayoutResId()== R_AVKON_STATUS_PANE_LAYOUT_EMPTY)
- {
- statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL);
- }
- AppUi()->ActivateLocalViewL(TUid::Uid(ESmsCheatMainView));
- }
- void CSplashWindowView::DoCancel()
- {
- iTimer.Cancel();
- }
- TInt CSplashWindowView::RunError(TInt aError)
- {
- return aError;
- }
- // End of File
UI类里需要修改的:
在ConstructL()中加入
- CEikStatusPane* statusPane =StatusPane();
- if ( statusPane->CurrentLayoutResId()!= R_AVKON_STATUS_PANE_LAYOUT_EMPTY)
- {
- statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
- }
在CSplashWindowContainer中完成图片的绘制,我使用的SVG图片
CFbsBitmap* iBkImage;
CFbsBitmap* iBkImageMask;
TSize iSize;
- void CSplashWindowContainer::ConstructL(const TRect& aRect)
- {
- CreateWindowL();
- TFileName fullname(KIconFileName);
- iSize.iHeight=88;
- iSize.iWidth=88;
- AknIconUtils::CreateIconL(iBkImage, iBkImageMask, fullname, EMbmSmscheat_bmpQgn_menu, EMbmSmscheat_bmpQgn_menu_mask);
- AknIconUtils::SetSize(iBkImage, iSize, EAspectRatioPreserved);
- SetRect(aRect);
- ActivateL();
- }
- void CSplashWindowContainer::Draw(const TRect& aRect) const
- {
- CWindowGc& gc = SystemGc();
- TPoint pn;
- pn.iX=aRect.Width()/2-iSize.iWidth/2;
- pn.iY=aRect.Height()/2-iSize.iHeight/2;
- gc.BitBltMasked(pn,iBkImage,iSize,iBkImageMask,ETrue);
- }
完成,图片显示的时间可设置,大小可设置。