⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 colorcontainer.cpp

📁 symbian有关文件操作的一个很好的例子
💻 CPP
字号:

#include <gulicon.h>
#include <aknutils.h>
#include <avkon.hrh>
#include <akntitle.h>
#include <HelloLDCI.rsg>
#include <helloldci.mbg>
#include <eiklabel.h>
#include <barsread.h>
#include <eikedwin.h>
#include <Aknnumseced.h> 
#include "HelloLDCIAppUi.h"
#include "ColorContainer.h"


CColorContainer::CColorContainer()
{
	//2-14
	m_pLabel	= NULL;
	m_pLabel2	= NULL;
	m_pEdwin	= NULL;
	m_pEdwin2	= NULL;
	m_pEdScrect = NULL;
	m_nDrawEditRectFlag = 0;
}

// EPOC default constructor can leave.
void CColorContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	//2-14
	//通过资源构建Label
	m_pLabel = new (ELeave)CEikLabel;
	m_pLabel->SetContainerWindowL(*this);
	//读取资源
	TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader, R_COLOR_LABEL);
	m_pLabel->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy();
	//设置Label的位置
	m_pLabel->SetExtent(TPoint(20,20),m_pLabel->MinimumSize());
    
	m_pLabel2 = new(ELeave)CEikLabel;
	m_pLabel2->SetContainerWindowL(*this);
	m_pLabel2->SetTextL(_L("World:"));
	m_pLabel2->SetExtent(TPoint(20,50),m_pLabel2->MinimumSize());
	
	//Editor 从资源创建
	m_pEdwin = new(ELeave) CEikEdwin; 		
	m_pEdwin->SetContainerWindowL(*this); 
	//TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader, R_COLOR_EDIT);
	m_pEdwin->ConstructFromResourceL(reader);
	CleanupStack::PopAndDestroy();	
	//设置当前输入为数字
	m_pEdwin->SetAknEditorCurrentInputMode
(EAknEditorNumericInputMode);
	m_pEdwin->SetExtent(TPoint(70,20), TSize(80,20)); 		
	
//	m_pRssEdit->SetTextL(&_L("Edit from Rss: Pass Word!")); 	
	m_pEdwin->SetFocus(ETrue);
	//使用代码动态创建编辑框
	m_pEdwin2 = new(ELeave) CEikEdwin; 		
	m_pEdwin2->SetContainerWindowL(*this);
	m_pEdwin2->ConstructL(EEikEdwinWidthInPixels,0,11,1);
	m_pEdwin2->SetExtent(TPoint(70,50), TSize(80,20));
	m_pEdwin2->SetFocus(EFalse); 


	//创建密码框:
// 	m_pEdScrect = new(ELeave)CAknNumericSecretEditor;
// 	m_pEdScrect->SetContainerWindowL(*this);
// 	iCoeEnv->CreateResourceReaderLC(reader, R_COLOR_EDIT);
// 	m_pEdScrect->ConstructFromResourceL(reader);
// 	m_pEdScrect->SetExtent(TPoint(20,100),TSize(80,20));
// 	m_pEdScrect->SetFocus(ETrue);
// 	CleanupStack::PopAndDestroy();
	SetRect( aRect );
    ActivateL();
}

// destructor
CColorContainer::~CColorContainer()
{
	//2-14
	if (m_pLabel)
	{
		delete m_pLabel;
		m_pLabel = NULL;
	}
	if (m_pLabel2)
	{
		delete m_pLabel2;
		m_pLabel2 = NULL;
	}
	if (m_pEdwin)
	{
		delete m_pEdwin;
		m_pEdwin = NULL;
	}
	if (m_pEdwin2)
	{
		delete m_pEdwin2;
		m_pEdwin2 = NULL;
	}
	if (m_pEdScrect)
	{
		delete m_pEdScrect;
		m_pEdScrect = NULL;
	}
}

void CColorContainer::SizeChanged()
{
}

// ---------------------------------------------------------
// CColorContainer::CountComponentControls() const
// return the number of controls
// ---------------------------------------------------------
//
TInt CColorContainer::CountComponentControls() const
{
	// return number of controls inside this container
	return 4;//5; 
}

// ---------------------------------------------------------
// CColorContainer::ComponentControl(TInt aIndex) const
// return the pointer to specified control.
// ---------------------------------------------------------
//
CCoeControl* CColorContainer::ComponentControl( TInt aIndex ) const
{
	switch(aIndex)
	{
	case 0:
		return m_pLabel;
	case 1:
	    return m_pLabel2;
	case 2:
		return m_pEdwin;
	case 3:
		return m_pEdwin2;
// 	case 4:
// 		return m_pEdScrect;
	default:
		return NULL;
	    break;
	}
}

// ---------------------------------------------------------
// CColorContainer::Draw(const TRect& aRect) const
// handle the message when client region must be redrawn.
// ---------------------------------------------------------
//
void CColorContainer::Draw( const TRect& /*aRect*/ ) const
{
	
	CWindowGc& gc = SystemGc();
	gc.Clear(Rect());
//添加背景图片
	TBuf<KMaxPath> pathMbm;
#ifdef __WINS__
	pathMbm.Copy(_L("z:\\system\\apps\\HELLOLDCI\\helloldci.mbm"));
#else
	CHelloLDCIAppUi* pApp = (CHelloLDCIAppUi*)CEikonEnv::Static()->AppUi();
	pApp->GetAppPath(pathMbm);
	pathMbm.Append(_L("helloldci.mbm"));
#endif
	//绘制背景图片
	CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL(pathMbm, EMbmHelloldciBlackground_i);
	gc.BitBlt(TPoint(0, 0), bitmap);
	delete bitmap;

	//绘制焦点框
	switch (m_nDrawEditRectFlag)
	{
	case 0:
		{
			gc.DrawRect(TRect(TPoint(69,19), TSize(82,22)));
			break;
		}
	case 1:
		{
			gc.DrawRect(TRect(TPoint(69,59), TSize(82,22)));
			break;
		}
	}
}

// ---------------------------------------------------------
// CAknExGridContainer::OfferKeyEventL(
//           const TKeyEvent& aKeyEvent, TEventCode aType )
// Handles the key events.
// ---------------------------------------------------------
//
TKeyResponse CColorContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
{
	//处理按键2-14
	if (m_pEdwin)
	{
		if (m_pEdwin->IsFocused())
		{
			if (aType == EEventKey && aKeyEvent.iCode == EKeyDownArrow)
			{
				m_pEdwin->SetFocus(EFalse);
				m_pEdwin2->SetFocus(ETrue);
				m_nDrawEditRectFlag = 1;
				DrawNow();
				return EKeyWasConsumed;
			}
			return m_pEdwin->OfferKeyEventL(aKeyEvent,aType);
		}
		
	}
	if (m_pEdwin2)
	{
		if (m_pEdwin2->IsFocused())
		{
			if (aType == EEventKey && aKeyEvent.iCode == EKeyUpArrow)
			{
				m_pEdwin2->SetFocus(EFalse);
				m_pEdwin->SetFocus(ETrue);
				m_nDrawEditRectFlag = 0;
				DrawNow();
				return EKeyWasConsumed;
			}
			return m_pEdwin2->OfferKeyEventL(aKeyEvent,aType);
		}
		
	}
	if (m_pEdScrect)
	{
		if (m_pEdScrect->IsFocused())
		{
			return m_pEdScrect->OfferKeyEventL(aKeyEvent,aType);
		}
	}
	
	//return m_pEdwin->OfferKeyEventL(aKeyEvent,aType);
}

void CColorContainer::GetEditText(TDes& aDes)
{
	m_pEdwin->GetText(aDes);
}

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -