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

📄 emptycontainer.cpp

📁 Symbian 第三版的一个传统应用程序构架的例子。Container容器为其构架类
💻 CPP
字号:
#include <eiklabel.h> 
#include <eikenv.h>
#include <gdi.h>
#include <charconv.h>
#include <e32cons.h>
#include <aknenv.h>
#include <aknutils.h>
#include <e32def.h>

#include "Empty.rsg"
#include "EmptyUi.h"
#include "EmptyContainer.h"
#include "Empty.h"
#include "..\help\Empty.hlp.hrh"

void CEmptyContainer::ConstructL(const TRect& aRect)
	{
	CreateWindowL();

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL( *this );
	iLabel->SetTextL(_L("first window"));
	
	//另外一种显示中文的方法。。。
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
	TBool chineseLanguageSupported = EFalse;

	if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
		iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}
	else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
		iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}
	TText8  *str = (TText8*)"拍拍365";
    TInt state=CCnvCharacterSetConverter::KStateDefault;

	TPtrC8 source( str );
	iInfoText = HBufC::NewL( source.Length() );
	TPtr16 ptr = iInfoText->Des();

	if( chineseLanguageSupported )
		{
		TRAP_IGNORE( converter->ConvertToUnicode( ptr, source, state ) );
		}
	
	//到此...........
	
	
	CleanupStack::PopAndDestroy();  // converter

    SetRect( aRect );
    ActivateL();
	}

void CEmptyContainer2::ConstructL(const TRect& aRect,CEmptyContainer2* iAppContainer2)
	{
// Create a window for this application view
    CreateWindowL();//复合控件创建窗口

    iLabel2=new(ELeave) CEikLabel;
    iLabel2->SetContainerWindowL(*iAppContainer2);//将不拥有窗口的控件和窗口关联
    iLabel2->SetTextL(_L("sencond window"));
	//另外一种显示中文的方法。。。
	CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC();
	TBool chineseLanguageSupported = EFalse;

	if( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGbk,
		iEikonEnv->FsSession()) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}
	else if ( converter->PrepareToConvertToOrFromL( KCharacterSetIdentifierGb2312,
		iEikonEnv->FsSession() ) == CCnvCharacterSetConverter::EAvailable )
		{
		chineseLanguageSupported = ETrue;
		}
	TText8  *str = (TText8*)"不要365";
    TInt state=CCnvCharacterSetConverter::KStateDefault;

	TPtrC8 source( str );
	iInfoText2 = HBufC::NewL( source.Length() );
	TPtr16 ptr = iInfoText2->Des();

	if( chineseLanguageSupported )
		{
		TRAP_IGNORE( converter->ConvertToUnicode( ptr, source, state ) );
		}
	
	//到此...........  	   	
    	CleanupStack::PopAndDestroy();  // converter
    // Set the windows size
    SetRect(aRect); 
    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }

CEmptyContainer::~CEmptyContainer()
	{
	delete iLabel;
	delete iInfoText;
	//指针为空吗? iLabel=NULL
	}

CEmptyContainer2::~CEmptyContainer2()
	{
	delete iLabel2;
	delete iInfoText2;
	}
void CEmptyContainer::SizeChanged()
	{
	iLabel->SetExtent( TPoint( 10,10 ), iLabel->MinimumSize());
	}
void CEmptyContainer2::SizeChanged()
	{
	iLabel2->SetExtent( TPoint( 10,10 ), iLabel2->MinimumSize());
	}

TInt CEmptyContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }
TInt CEmptyContainer2::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }
CCoeControl* CEmptyContainer::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel;
        default:
            return NULL;
        }
    }
CCoeControl* CEmptyContainer2::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        case 0:
            return iLabel2;
        default:
            return NULL;
        }
    }
void CEmptyContainer::Draw(const TRect& aRect) const
	{
    CWindowGc& gc = SystemGc();

    gc.SetPenStyle( CGraphicsContext::ESolidPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect(aRect);

	const CFont* font;
	// Define the buffer to display
	TBuf<KMaxStringLength> buf;
	
	TLanguage language =  User::Language(); 

	if ( language == ELangPrcChinese || 
		 language == ELangTaiwanChinese ||
		 language == ELangHongKongChinese )
		{
		font = ApacPlain16();
		buf.Copy(iInfoText->Des());
		
		TRect rect = Rect();

		// Use system font
		gc.UseFont( font );
		TInt baseline = rect.Height()/2 + font->AscentInPixels()/2 - 10;
		gc.DrawText( buf, rect, baseline, CGraphicsContext::ECenter );
		}
    }
void CEmptyContainer2::Draw(const TRect& aRect) const
	{
    CWindowGc& gc = SystemGc();

    gc.SetPenStyle( CGraphicsContext::ESolidPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect(aRect);

	const CFont* font;
	// Define the buffer to display
	TBuf<KMaxStringLength> buf;
	
	TLanguage language =  User::Language(); 

	if ( language == ELangPrcChinese || 
		 language == ELangTaiwanChinese ||
		 language == ELangHongKongChinese )
		{
		font = ApacPlain16();
		buf.Copy(iInfoText2->Des());		
		TRect rect = Rect();
		// Use system font
		gc.UseFont( font );
		TInt baseline = rect.Height()/2 + font->AscentInPixels()/2 - 10;
		gc.DrawText( buf, rect, baseline, CGraphicsContext::ECenter );
		}
    }	
void CEmptyContainer::HandleControlEventL(
		CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
	{
	
	}
void CEmptyContainer2::HandleControlEventL(
		CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
	{
	
	}
void CEmptyContainer::GetHelpContext(TCoeHelpContext& aContext ) const
	{
    
	aContext.iMajor = KUidEmpty;
    aContext.iContext = KContextChinese;
	}

void CEmptyContainer2::GetHelpContext(TCoeHelpContext& aContext ) const
	{
    
	aContext.iMajor = KUidEmpty;
    aContext.iContext = KContextChinese;
	}

/*void CEmptyContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
	{
	
	}

void CEmptyContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
	{
	
	}
*/

⌨️ 快捷键说明

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