symbian自定义闪烁图片控件
来源:互联网 发布:专业mtv制作软件 编辑:程序博客网 时间:2024/05/17 04:58
下面是自定义的一个图片控件,实现的功能是在屏幕上显示一张一闪一闪的图片,并且能够根据用户输入上下左右键进行移动
加载图片,首先要在mmp文件中增添以下代码(红色为增添部分)
/*
============================================================================
Name : SelfControl.mmp
Author :
Version :
Copyright : Your copyright notice
Description : This is the project specification file for SelfControl.
============================================================================
*/
TARGET SelfControl.app
TARGETTYPE app
UID 0x100039CE 0x0897af2b
TARGETPATH /system/apps/SelfControl
SOURCEPATH ../data
RESOURCE SelfControl.rss
RESOURCE SelfControl_caption.rss
============================================================================
Name : SelfControl.mmp
Author :
Version :
Copyright : Your copyright notice
Description : This is the project specification file for SelfControl.
============================================================================
*/
TARGET SelfControl.app
TARGETTYPE app
UID 0x100039CE 0x0897af2b
TARGETPATH /system/apps/SelfControl
SOURCEPATH ../data
RESOURCE SelfControl.rss
RESOURCE SelfControl_caption.rss
SOURCEPATH ../src
SOURCE CBlinkImage.cpp
SOURCE SelfControlApp.cpp
SOURCE SelfControlAppui.cpp
SOURCE SelfControlDocument.cpp
SOURCE SelfControlContainer.cpp
SOURCE CBlinkImage.cpp
SOURCE SelfControlApp.cpp
SOURCE SelfControlAppui.cpp
SOURCE SelfControlDocument.cpp
SOURCE SelfControlContainer.cpp
LANG SC
USERINCLUDE .
USERINCLUDE ../inc
SYSTEMINCLUDE .
SYSTEMINCLUDE /epoc32/include
/* [+] */ LIBRARY fbscli.lib
LIBRARY euser.lib
LIBRARY apparc.lib
LIBRARY cone.lib
LIBRARY eikcore.lib
LIBRARY eikcoctl.lib
LIBRARY avkon.lib
AIF SelfControl.aif ../aif SelfControlaif.rss c8 context_pane_icon.bmp context_pane_icon_mask.bmp list_icon.bmp list_icon_mask.bmp
START BITMAP bmp.mbm
TARGETPATH // //目标文件夹,相对于手机Z盘来说的
HEADER
SOURCEPATH ../aif //图片所在文件夹,这个路径是相对于该mmp文件所在的路径而言的
SOURCE c12 image1.bmp //图片名为image1.bmp
USERINCLUDE .
USERINCLUDE ../inc
SYSTEMINCLUDE .
SYSTEMINCLUDE /epoc32/include
/* [+] */ LIBRARY fbscli.lib
LIBRARY euser.lib
LIBRARY apparc.lib
LIBRARY cone.lib
LIBRARY eikcore.lib
LIBRARY eikcoctl.lib
LIBRARY avkon.lib
AIF SelfControl.aif ../aif SelfControlaif.rss c8 context_pane_icon.bmp context_pane_icon_mask.bmp list_icon.bmp list_icon_mask.bmp
START BITMAP bmp.mbm
TARGETPATH // //目标文件夹,相对于手机Z盘来说的
HEADER
SOURCEPATH ../aif //图片所在文件夹,这个路径是相对于该mmp文件所在的路径而言的
SOURCE c12 image1.bmp //图片名为image1.bmp
END
编译该工程后会在z盘目录下产生一个bmp.mbm文件以及在epoc32/include目录下产生bmp.mbg文件
bmp.mbg文件内容如下:
// bmp.mbg
// Generated by BitmapCompiler
// Copyright (c) 1998-2001 Symbian Ltd. All rights reserved.
//
// Generated by BitmapCompiler
// Copyright (c) 1998-2001 Symbian Ltd. All rights reserved.
//
enum TMbmBmp
{
EMbmBmpImage1//在源程序中访问那张图片要用这个标识
};
{
EMbmBmpImage1//在源程序中访问那张图片要用这个标识
};
头文件:
#ifndef CBLINKIMAGE_H
#define CBLINKIMAGE_H
#define CBLINKIMAGE_H
#include<coecntrl.h>
#include "fbs.h"
class CBlinkImage:public CCoeControl
{
public:
CBlinkImage(CCoeControl& aParent);
void ConstructL(CCoeControl& aParent);
~CBlinkImage();
void Draw(const TRect& aRect) const;
void Start(TTimeIntervalMicroSeconds32 aInterval);
void Stop();
#include "fbs.h"
class CBlinkImage:public CCoeControl
{
public:
CBlinkImage(CCoeControl& aParent);
void ConstructL(CCoeControl& aParent);
~CBlinkImage();
void Draw(const TRect& aRect) const;
void Start(TTimeIntervalMicroSeconds32 aInterval);
void Stop();
private:
void SizeChanged();
static TInt Tick(TAny* aThis);
void DoTick();
private:
CFbsBitmap* m_pMap;
CPeriodic* iTicker;
//CCoeControl* m_pContainer;
int m_Count;
bool m_bDrawBitmap;
};
#endif
void SizeChanged();
static TInt Tick(TAny* aThis);
void DoTick();
private:
CFbsBitmap* m_pMap;
CPeriodic* iTicker;
//CCoeControl* m_pContainer;
int m_Count;
bool m_bDrawBitmap;
};
#endif
源文件:
#include "CBlinkImage.h"
#include "C:/Symbian/8.0a/S60_2nd_FP2_SC/epoc32/include/bmp.mbg"//为访问图片
#include "fbs.h"
#include "e32math.h"
#include "C:/Symbian/8.0a/S60_2nd_FP2_SC/epoc32/include/bmp.mbg"//为访问图片
#include "fbs.h"
#include "e32math.h"
CBlinkImage::CBlinkImage(CCoeControl& aParent)
:m_bDrawBitmap(false),m_pList(0)
{
ConstructL(aParent);
}
:m_bDrawBitmap(false),m_pList(0)
{
ConstructL(aParent);
}
void CBlinkImage::ConstructL(CCoeControl& aParent)
{
_LIT(sFilePath,"Z://bmp.mbm");
{
_LIT(sFilePath,"Z://bmp.mbm");
//编译后产生的bmp.mbm文件所在位置,注意是相对于symbian操作系统的z盘来设置的。这个文件在我的电脑上的路径其实是
// C:/Symbian/8.0a/S60_2nd_FP2_SC/epoc32/release/wins/udeb/z/bmp.mbm
SetContainerWindowL(aParent);//设置图片控件的父亲控件
m_pMap = new(ELeave) CFbsBitmap();
User::LeaveIfError(m_pMap->Load(sFilePath,EMbmBmpImage1));//加载图片
iTicker = CPeriodic::NewL(CActive::EPriorityIdle);
this->SetRect(TRect( TPoint(20,20),TSize(40,40) ));
Start(100000);
ActivateL();
}
SetContainerWindowL(aParent);//设置图片控件的父亲控件
m_pMap = new(ELeave) CFbsBitmap();
User::LeaveIfError(m_pMap->Load(sFilePath,EMbmBmpImage1));//加载图片
iTicker = CPeriodic::NewL(CActive::EPriorityIdle);
this->SetRect(TRect( TPoint(20,20),TSize(40,40) ));
Start(100000);
ActivateL();
}
CBlinkImage::~CBlinkImage()
{
if(iTicker)
iTicker->Cancel();
if(m_pMap)
delete m_pMap;
}
void CBlinkImage::SizeChanged()
{
}
void CBlinkImage::Draw(const TRect& aRect) const
{////根据m_bDrawBitmap的值来决定怎样画这个控件
if (m_bDrawBitmap)
{
TRect rt = Rect();
SystemGc().BitBlt(rt.iTl, m_pMap);//画图
}
else
{
SystemGc().Clear();//清空屏幕
}
}
{////根据m_bDrawBitmap的值来决定怎样画这个控件
if (m_bDrawBitmap)
{
TRect rt = Rect();
SystemGc().BitBlt(rt.iTl, m_pMap);//画图
}
else
{
SystemGc().Clear();//清空屏幕
}
}
void CBlinkImage::Start(TTimeIntervalMicroSeconds32 aInterval)
{
iTicker->Start(aInterval, aInterval, TCallBack(Tick, this));
}
{
iTicker->Start(aInterval, aInterval, TCallBack(Tick, this));
}
void CBlinkImage::Stop()
{
iTicker->Cancel();
}
{
iTicker->Cancel();
}
TInt CBlinkImage::Tick(TAny* aThis)
{
static_cast<CBlinkImage*>(aThis)->DoTick();
return 0;
}
{
static_cast<CBlinkImage*>(aThis)->DoTick();
return 0;
}
void CBlinkImage::DoTick()
{
{
//每次调用DoTick()函数都会改变当前m_bDrawBitmap的值,然后调用DrawNow()函数重画图片,就能出现一闪一闪的效果
if(m_pMap)
{
if (m_bDrawBitmap==false)
{
m_bDrawBitmap = true;
}
else
{
m_bDrawBitmap = false;
}
DrawNow();//每次调用DrawNow()函数,框架会自动调用Draw()函数。
}
}
if(m_pMap)
{
if (m_bDrawBitmap==false)
{
m_bDrawBitmap = true;
}
else
{
m_bDrawBitmap = false;
}
DrawNow();//每次调用DrawNow()函数,框架会自动调用Draw()函数。
}
}
在类container中调用创建这个自定义的闪烁图标控件:
SelfControlContainer.cpp文件:
/*
============================================================================
Name : CSelfControlContainer from SelfControlContainer.h
Author :
Version :
Copyright : Your copyright notice
Description : Container control implementation
============================================================================
*/
============================================================================
Name : CSelfControlContainer from SelfControlContainer.h
Author :
Version :
Copyright : Your copyright notice
Description : Container control implementation
============================================================================
*/
// INCLUDE FILES
#include "SelfControlContainer.h"
#include "CBlinkImage.h"
#include <eiklabel.h> // for example label control
#include "SelfControlContainer.h"
#include "CBlinkImage.h"
#include <eiklabel.h> // for example label control
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CSelfControlContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSelfControlContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//x=10;
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("Example View") );
// CSelfControlContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSelfControlContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
//x=10;
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("Example View") );
iToDoLabel = new (ELeave) CEikLabel;
iToDoLabel->SetContainerWindowL( *this );
iToDoLabel->SetTextL( _L("Add Your controls/n here") );
iToDoLabel->SetContainerWindowL( *this );
iToDoLabel->SetTextL( _L("Add Your controls/n here") );
m_pBmp = new (ELeave) CBlinkImage( *this );
SetRect(aRect);
ActivateL();
}
// Destructor
CSelfControlContainer::~CSelfControlContainer()
{
delete iLabel;
delete iToDoLabel;
delete m_pBmp;
}
CSelfControlContainer::~CSelfControlContainer()
{
delete iLabel;
delete iToDoLabel;
delete m_pBmp;
}
// ---------------------------------------------------------
// CSelfControlContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSelfControlContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}
// CSelfControlContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSelfControlContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
iLabel->SetExtent( TPoint(10,10), iLabel->MinimumSize() );
iToDoLabel->SetExtent( TPoint(10,100), iToDoLabel->MinimumSize() );
}
// ---------------------------------------------------------
// CSelfControlContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSelfControlContainer::CountComponentControls() const
{
return 3; // return nbr of controls inside this container
}
// CSelfControlContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSelfControlContainer::CountComponentControls() const
{
return 3; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSelfControlContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSelfControlContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iToDoLabel;
case 2:
return m_pBmp;
default:
return NULL;
}
}
// CSelfControlContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSelfControlContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
case 1:
return iToDoLabel;
case 2:
return m_pBmp;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CSelfControlContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSelfControlContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear();
}
// CSelfControlContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSelfControlContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear();
}
// ---------------------------------------------------------
// CSelfControlContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSelfControlContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
// CSelfControlContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSelfControlContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
//响应按键事件
TKeyResponse CSelfControlContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
TRect rt = m_pBmp->Rect();
switch(aKeyEvent.iCode)
{
case EKeyDownArrow:
rt.Move(0,3);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyLeftArrow:
rt.Move(-3,0);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyUpArrow:
rt.Move(0,-3);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyRightArrow:
rt.Move(3,0);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
default:
break;
}
return EKeyWasNotConsumed;
}
TKeyResponse CSelfControlContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
TRect rt = m_pBmp->Rect();
switch(aKeyEvent.iCode)
{
case EKeyDownArrow:
rt.Move(0,3);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyLeftArrow:
rt.Move(-3,0);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyUpArrow:
rt.Move(0,-3);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
case EKeyRightArrow:
rt.Move(3,0);
m_pBmp->SetRect(rt);
DrawNow();
return EKeyWasConsumed;
break;
default:
break;
}
return EKeyWasNotConsumed;
}
- symbian自定义闪烁图片控件
- symbian中自定义控件
- Symbian 自定义控件
- C#自定义控件-消除闪烁
- Winform 自定义控件闪烁问题
- C# 自定义控件闪烁 UserControl
- Timer控件实现图片闪烁
- 自定义的symbian图片控件,可在任意的位置放图片
- 自定义的symbian图片控件,可在任意的位置放图片
- 自定义的symbian图片控件,可在任意的位置放图片
- Symbian OS: 创建自定义控件
- symbian 自定义控件 滚动条
- 解决自定义控件闪烁的问题
- Android运用自定义控件实现闪烁字
- c# 自定义控件 属性菜单 控件移动 闪烁
- 自定义控件--图片按钮
- 自定义圆形图片控件
- 自定义圆形图片控件
- HTML乱码
- SOA的实施之“道”—中间相遇
- Oracle 客户端连接服务器常见问题之--------ORA-12154: TNS: could not resolve service name
- 创建最简单的HelloWorld业务规则
- 从买硬盘来看建造者模式+vb.net实现
- symbian自定义闪烁图片控件
- JavaMail中Session.getDefaultInstance的应用
- 在Flash应用中使用动态变量
- Windows7 使用的问题和相关处理
- 执行力第一
- java专业术语标准化规范表
- SOA常见问题
- 未来3年SAP实施顾问职业生涯分析 (转载)
- C#多线程与UI响应