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

📄 logoncontainer.cpp

📁 一个比较完整的有关移动开发的例子 vc++6.0下编译通过
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CLogonContainer from CCoeControl, MCoeControlObserver
*  Part of  : Logon
*  Copyright (c) 2003 Nokia. All rights reserved.
* ============================================================================
*/

// INCLUDE FILES

#define MEM_FREE(q) if (NULL!=q){delete q; q = NULL;}

#include <FairyLand.rsg>
#include "FairyLand.hrh"
#include "LogonContainer.h"
#include "FairyLandappui.h"

#include <eiklabel.h>	//for CEikLabel
#include <eikedwin.h> //for CEikEdwin
#include <barsread.h>	//for resource reader

#include <AknNumSecEd.h> 


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

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

    }

// EPOC default constructor can leave.
void CLogonContainer::ConstructL(const TRect& aRect,HBufC *aName)
    {
    CreateWindowL();
	TBuf<32> LogonName;
	CEikonEnv::Static()->ReadResource(LogonName, R_QTN_MH_LOGON_LABEL_NAME);
	TBuf<32> LogonPassWord;
	CEikonEnv::Static()->ReadResource(LogonPassWord, R_QTN_MH_LOGON_LABEL_PASSWORD);
	
	//Label1
	m_pLabel1 = new(ELeave) CEikLabel;
	m_pLabel1->SetContainerWindowL(*this);
	m_pLabel1->SetTextL(LogonName);
	m_pLabel1->SetExtent(TPoint(20,20), m_pLabel1->MinimumSize());
	
	//Label2
	m_pLabel2 = new(ELeave) CEikLabel;
	m_pLabel2->SetContainerWindowL(*this);
	m_pLabel2->SetTextL(LogonPassWord);
	m_pLabel2->SetExtent(TPoint(20,60), m_pLabel2->MinimumSize());


	
	//Edit1
	m_pEdit1 = new(ELeave) CEikEdwin;
	m_pEdit1->SetContainerWindowL(*this);
	m_pEdit1->ConstructL(EAknEditorFlagDefault, 10, 10, 1);
	m_pEdit1->SetExtent(TPoint(70,20), TSize(80,20));
	m_pEdit1->SetTextL(&aName->Des());
	m_pEdit1->SetFocus(EFalse);


	//Edit2
	m_pEdit2 = new(ELeave)CAknNumericSecretEditor;
	m_pEdit2->SetContainerWindowL(*this);   
	TResourceReader read;
	CEikonEnv::Static()->CreateResourceReaderLC(read,R_MY_SEC_ED);   
	m_pEdit2->ConstructFromResourceL(read);  
	CleanupStack::PopAndDestroy();  
    m_pEdit2->SetExtent( TPoint( 70,60 ),TSize( 80,20 ) );
	m_pEdit2->SetFocus(ETrue);

	

    SetRect(aRect);
    ActivateL();
    }

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

    }

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

void CLogonContainer::FocusTo(TInt aCommand)
    {
    }

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

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

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

	case 2:
		{
			return m_pEdit1;
			break;
		}
	case 3:
		{
			return m_pEdit2;
			break;
		}

	default:
		{
			return NULL;
			break;
		}
	}	
    }
// ---------------------------------------------------------
// CLogonContainer::Draw(const TRect& aRect) const
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CLogonContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle(CGraphicsContext::ENullPen);
    gc.SetBrushColor(KRgbCyan);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.DrawRect(aRect);


     //画线
	//	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	//	gc.SetPenColor(KRgbYellow);
	//	TPoint startPos(20, 30);       
	//	TPoint endPos(20, 80);
	//	gc.DrawLine(startPos, endPos);

// 	TBuf<32> LogonName;
// 	CEikonEnv::Static()->ReadResource(LogonName, R_QTN_MH_LOGON_LABEL_NAME);
// 
// 		TPoint point(aRect.Width() / 2 - 50, aRect.Height() / 2);
// 		gc.DrawText(buf, point);
// 	 	point.iX += 35;
// 		gc.DrawText(LogonName,point);
// 	 	gc.DiscardFont();



    }

// ---------------------------------------------------------
// CLogonContainer::OfferKeyEventL(...)
// Notify key events to editors.
// (other items were commented in a header).
// ---------------------------------------------------------
//
TKeyResponse CLogonContainer::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);
				return EKeyWasConsumed;
			}
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pEdit1->SetFocus(EFalse);
				m_pEdit2->SetFocus(ETrue);
				return EKeyWasConsumed;
			}
			return m_pEdit1->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	if (m_pEdit2)
	{
		if (m_pEdit2->IsFocused())
		{
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyDownArrow))
			{
				m_pEdit1->SetFocus(ETrue);
				m_pEdit2->SetFocus(EFalse);
				return EKeyWasConsumed;
			}
			if((aType == EEventKey) && (aKeyEvent.iCode == EKeyUpArrow))
			{
				m_pEdit2->SetFocus(EFalse);
				m_pEdit1->SetFocus(ETrue);
			}
			return m_pEdit2->OfferKeyEventL(aKeyEvent, aType);
		}
	}
	
	return EKeyWasNotConsumed;
}






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

void CLogonContainer::GetLogonName(TDes &aName)
{
	m_pEdit1->GetText(aName);
}
void CLogonContainer::GetLogonPassWord(TDes &Password)
{
	m_pEdit2->GetText(Password);
}
// End of File  

⌨️ 快捷键说明

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