功能:可以在窗口上显示一个浮动图标。如果需要在待机界面上显示,而在别的界面上不显示,需要修改。
此代码在第五版上测试通过。
/*
* ============================================================================
* Name : CIndicatorIcon from CCoeControl
* Part of : IndicatorIconEx
* Created : 01/11/2006 by Vinod Kumar K V
* Description:
* Some utility functions.
* Version :
* Copyright: Copyright (c) 1999 - 2006 Vinsofts Inc.
* (http://cc.1asphost.com/vinsofts/)
* ============================================================================
*/
#ifndef INDICATORICON_H
#define INDICATORICON_H
// INCLUDES
#include <aknview.h>
#include <FBS.H>
// FORWARD DECLARATIONS
class RWindowGroup;
// CLASS DECLARATION
class CIndicatorIcon : public CCoeControl
{
public:
public:
static CIndicatorIcon* NewL();
static CIndicatorIcon* NewLC();
virtual ~CIndicatorIcon();
private:
CIndicatorIcon();
void ConstructL();
private:
void Draw(const TRect& aRect) const;
//触屏
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
private:
RWindowGroup iMyWindowGroup;
CFbsBitmap *iIndicator;
CFbsBitmap *iIndicatorMask;
private:
//是否刷新窗口
void SetIndicatorIconL(TBool aRedraw = EFalse);
//显示程序
void ShowApp();
public:
//显示图标
void ShowICON();
//隐藏图标
void HideICON();
};
#endif // INDICATORICON_H
// End of File
/*
* ============================================================================
* Name : CIndicatorIcon from CCoeControl
* Part of : IndicatorIconEx
* Created : 01/11/2006 by Vinod Kumar K V
* Description:
* Some utility functions.
* Version :
* Copyright: Copyright (c) 1999 - 2006 Vinsofts Inc.
* (http://cc.1asphost.com/vinsofts/)
* ============================================================================
*/
// INCLUDE FILES
#include <APGTASK.H>
#include <akncontext.h>
#include <fbs.h>
#include <aknutils.h>
#include <eikenv.h>
#include "S5TestNO3.mbg"
#include <avkon.mbg>
#include "IndicatorIcon.h"
// CONSTANTS
/*
const TInt KIndicatorPosX = 152;
const TInt KIndicatorPosY = 12;
*/
const TInt KIndicatorPosX = 80;
const TInt KIndicatorPosY = 190;
// ================= MEMBER FUNCTIONS =======================
// ----------------------------------------------------------------------------
// CIndicatorIcon::NewL()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CIndicatorIcon* CIndicatorIcon::NewL()
{
CIndicatorIcon* self = CIndicatorIcon::NewLC();
CleanupStack::Pop(self);
return self;
}
// ----------------------------------------------------------------------------
// CIndicatorIcon::NewLC()
// Two-phased constructor.
// ----------------------------------------------------------------------------
//
CIndicatorIcon* CIndicatorIcon::NewLC()
{
CIndicatorIcon* self = new (ELeave) CIndicatorIcon();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// ----------------------------------------------------------
// CIndicatorIcon::CIndicatorIcon()
//
// C++ default constructor can NOT contain any code, that
// might leave.
// ----------------------------------------------------------
//
CIndicatorIcon::CIndicatorIcon()
{
}
// ----------------------------------------------------------
// CIndicatorIcon::ConstructL(const TRect& aRect)
//
// EPOC default constructor can leave.
// ----------------------------------------------------------
//
void CIndicatorIcon::ConstructL()
{
iMyWindowGroup = RWindowGroup(iCoeEnv->WsSession());
User::LeaveIfError(iMyWindowGroup.Construct((TUint32) &iMyWindowGroup));
iMyWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
iMyWindowGroup.EnableReceiptOfFocus(EFalse);
CreateWindowL(&iMyWindowGroup);
//
_LIT(KBitmapPath , "//resource//apps//S5TestNO3.mbm");
//引入图片的路径
TFileName filename(KBitmapPath);
User::LeaveIfError(CompleteWithAppPath(filename));
if (iIndicator)
delete iIndicator;
if (iIndicatorMask)
delete iIndicatorMask;
iIndicator = new (ELeave) CFbsBitmap;
iIndicatorMask = new (ELeave) CFbsBitmap;
iIndicator->Load(filename, EMbmS5testno3A);
iIndicatorMask->Load(filename, EMbmS5testno3A_mask);
//隐藏
HideICON();
ActivateL();
}
// ----------------------------------------------------------
// CIndicatorIcon::~CIndicatorIcon()
//
// Destructor
// ----------------------------------------------------------
//
CIndicatorIcon::~CIndicatorIcon()
{
if (iIndicator)
{
delete iIndicator;
iIndicator = NULL;
} // if (iIndicator)
if (iIndicatorMask)
{
delete iIndicatorMask;
iIndicatorMask = NULL;
} // if (iIndicatorMask)
iMyWindowGroup.Close();
}
// ---------------------------------------------------------
// CIndicatorIcon::SetIndicatorIconL(TInt aIconType)
//
// Set the indicator icon.
// ---------------------------------------------------------
//
void CIndicatorIcon::SetIndicatorIconL(TBool aRedraw)
{
if (!aRedraw)
{
return;
}
DrawNow();
}
// ---------------------------------------------------------
// CIndicatorIcon::Draw(const TRect& aRect) const
//
// Draw function.
// ---------------------------------------------------------
//
void CIndicatorIcon::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear();
gc.BitBltMasked(TPoint(aRect.iTl.iX, aRect.iTl.iY), iIndicator, TRect(
TPoint(0, 0), iIndicator->SizeInPixels()), iIndicatorMask, ETrue);
}
void CIndicatorIcon::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
if (1 == aPointerEvent.iType)
{
ShowApp();
}
}
void CIndicatorIcon::ShowApp()
{
TApaTask task(CEikonEnv::Static()->WsSession());
task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());
task.BringToForeground();
}
//显示图标
void CIndicatorIcon::ShowICON()
{
SetRect(TRect(TPoint(KIndicatorPosX, KIndicatorPosY),
iIndicator->SizeInPixels()));
SetIndicatorIconL(ETrue);
}
//隐藏图标
void CIndicatorIcon::HideICON()
{
SetRect(TRect(TPoint(0, 0), TSize(0, 0)));
SetIndicatorIconL(EFalse);
}
浮动窗口的创建。
最新推荐文章于 2021-03-31 09:14:56 发布