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

📄 logincontainer.cpp

📁 symbian系统上的记事本程序
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CLoginContainer from CCoeControl, MCoeControlObserver
*  Part of  : Hello
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES


#include <EveryDay.rsg>
#include "EveryDay.hrh"
#include "LoginContainer.h"
#include <aknviewappui.h>
#include "Common.h"
#include <eiklabel.h>  //for CEikLabel
#include <eikedwin.h>  //for CEikEdit
#include <aknnotewrappers.h>
#include <barsread.h>
#include <aknnotewrappers.h>
#include <aknnumseced.h>
#include "EveryDayAppUi.h"
#include "File.h"

// ================= MEMBER FUNCTIONS =======================

// C++ default constructor can NOT contain any code, that
// might leave.
//
CLoginContainer::CLoginContainer()
{
	m_pLabel1 = NULL;
	m_pEdit1 = NULL;
	m_pLabel2 = NULL;
	m_pEdit2 = NULL;
}

// EPOC default constructor can leave.
void CLoginContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();
	
	//Label
	TBuf<32> Text;
	iEikonEnv->ReadResource(Text,R_QTN_MH_USERNAME_TITLE);
	m_pLabel1 = new(ELeave) CEikLabel;
	m_pLabel1->SetContainerWindowL(*this);
	m_pLabel1->SetTextL(Text);
	m_pLabel1->SetExtent(TPoint(10,20), m_pLabel1->MinimumSize());
	
	//Edit
	m_pEdit1 = new(ELeave) CEikEdwin;
	m_pEdit1->SetContainerWindowL(*this);
	m_pEdit1->ConstructL(EAknEditorFlagDefault, 10, 11, 1);
	m_pEdit1->SetExtent(TPoint(70,20), TSize(80,18)); //TPoint坐标起点,TSize方框大小
	m_pEdit1->SetAknEditorCurrentInputMode(EAknEditorNumericInputMode);//设置只能输入数字输入模式
	
	m_pEdit1->SetFocus(ETrue);//焦点
	
	//Label
	iEikonEnv->ReadResource(Text, R_QTN_MH_PASSWORD_TITLE);
	m_pLabel2 = new(ELeave) CEikLabel;
	m_pLabel2->SetContainerWindowL(*this);
	m_pLabel2->SetTextL(Text);//m_pLabel2->SetTextL(_L("Pass Word :"));
	m_pLabel2->SetExtent(TPoint(10,60), m_pLabel2->MinimumSize());
	
	//Edit
	TResourceReader reader1;
	iCoeEnv->CreateResourceReaderLC(reader1,R_PASSWORD_BUFNUM);
	m_pEdit2 = new (ELeave) CAknNumericSecretEditor() ;
	m_pEdit2->SetContainerWindowL(*this);
	m_pEdit2->ConstructFromResourceL(reader1);
	CleanupStack::PopAndDestroy();
	m_pEdit2->SetExtent(TPoint(70,60), TSize(80,18));
	m_pEdit2->SetFocus(EFalse);
	m_pEdit2->SetBorder(ENone);
	
    SetRect(aRect);
    ActivateL();
}

// Destructor
CLoginContainer::~CLoginContainer()
{
	MEM_FREE(m_pLabel1);
	MEM_FREE(m_pEdit1);
	MEM_FREE(m_pLabel2);
	MEM_FREE(m_pEdit2);
}

// ---------------------------------------------------------
// CLoginContainer::FocusTo(TInt aCommand)
// Change foccused control.
// (other items were commented in a header).
// ---------------------------------------------------------
//

void CLoginContainer::FocusTo(TInt aCommand)
{
}

// ---------------------------------------------------------
// CLoginContainer::SizeChanged()
// Called by framework when the view size is changed
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLoginContainer::SizeChanged()
{
}

// ---------------------------------------------------------
// CLoginContainer::CountComponentControls() const
// (other items were commented in a header).
// ---------------------------------------------------------
//
TInt CLoginContainer::CountComponentControls() const
{
	return 4; // return nbr of controls inside this container
}

// ---------------------------------------------------------
// CLoginContainer::ComponentControl(TInt aIndex) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
CCoeControl* CLoginContainer::ComponentControl(TInt aIndex) const
{
	//	return NULL;
	switch(aIndex)
	{
	case 0:
		{
			return m_pLabel1;
			break;
		}
	case 1:
		{
			return m_pEdit1;
			break;
		}
	case 2:
		{
			return m_pLabel2;
			break;
		}
	case 3:
		{
			return m_pEdit2;
			break;
		}
	default:
		{
			return NULL;
			break;
		}
	}
	
}

// ---------------------------------------------------------
// CLoginContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLoginContainer::Draw(const TRect& aRect) const
{
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbWhite);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);
	
	//画一长方形
	if(m_pEdit1->IsFocused()) // username 获得焦点 
	{
		gc.SetPenColor(KRgbRed);
	}
	else
	{
		gc.SetPenColor(KRgbBlack);
	}
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	
	TRect rect1;
	rect1.iTl = TPoint(69, 18);
	rect1.iBr = TPoint(152,40);
	gc.DrawRect(rect1);
	
	
	
	if(m_pEdit2->IsFocused())
	{
		gc.SetPenColor(KRgbRed);
	}
	else
	{
		gc.SetPenColor(KRgbBlack);
	}
	//画一长方形
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	TRect rect2;
	rect2.iTl = TPoint(69, 58);
	rect2.iBr = TPoint(152, 80);
	gc.DrawRect(rect2);
	
	
}

// ---------------------------------------------------------
// CLoginContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CLoginContainer::OfferKeyEventL(
											 const TKeyEvent& aKeyEvent, TEventCode aType)
{
	//	return EKeyWasNotConsumed;
	if (m_pEdit1)
	{
		if (m_pEdit1->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				m_pEdit1->SetFocus(EFalse);
				m_pEdit2->SetFocus(ETrue);
				DrawDeferred();
				return EKeyWasNotConsumed;
			}
			return m_pEdit1->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	if (m_pEdit2)
	{
		if(m_pEdit2->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pEdit1->SetFocus(ETrue);
				m_pEdit2->SetFocus(EFalse);
				DrawDeferred();
				return EKeyWasNotConsumed;
			}
			return m_pEdit2->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	return EKeyWasNotConsumed;
}


// ---------------------------------------------------------
// CLoginContainer::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLoginContainer::HandleControlEventL(
										  CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
}

void CLoginContainer::GetName(TDes& aName)
{
	m_pEdit1->GetText(aName);
}

void CLoginContainer::GetPassWord(TDes& aPassword)
{
	m_pEdit2->GetText(aPassword);
}
// End of File  

⌨️ 快捷键说明

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