Symbian 常用 Dialog
2010-02-09 03:55:00 来源:WEB开发网TBuf<128> iKeyText;
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC( reader, R_RESOURCE_EDITOR ); //从资源文件构造编辑框,资源见下面的定义
iGKeyEd = new ( ELeave ) CEikGlobalTextEditor;
iGKeyEd->SetContainerWindowL( *this );
iGKeyEd->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // Resource reader
//设置编辑框的初始文本和位置,编辑框大小在资源中定义
TBuf<32> buf;
buf.Copy(_L("demo"));
iGKeyEd->SetTextL(&buf);
iGKeyEd->SetExtent( TPoint(5,2), iGKeyEd->MinimumSize() );
iGKeyEd->SetFocus(ETrue);
// iGKeyEd->SetReadOnly(ETrue); //设置编辑框为只读
//使文字居中
CParaFormat paraFormat;
TParaFormatMask paraFormatMask;
paraFormatMask.SetAttrib( EAttAlignment ); // set mask
paraFormat.iHorizontalAlignment = CParaFormat::ECenterAlign;
iGKeyEd->ApplyParaFormatL( ¶Format, paraFormatMask );
iGKeyEd->GetText(iKeyText); //获取编辑框中的内容,保存到iKeyText中
RESOURCE GTXTED R_RESOURCE_EDITOR //编辑框资源
{
flags = EAknEditorFlagDefault;
width = 53;
height = 16;
numlines = 1;
textlimit= 1;
fontcontrolflags = EGulFontControlAll;
fontnameflags = EGulNoSymbolFonts;
//这里也可设置输入法
// avkon_flags = EAknEditorFlagFixedCase |
EAknEditorFlagNoT9 | EAknEditorFlagSupressShiftMenu; //EAknEditorFlagSupressShiftMenu屏蔽切换输入法键
// allowed_input_modes = EAknEditorNumericInputMode;
// default_input_mode = EAknEditorNumericInputMode;
// numeric_keymap = EAknEditorPlainNumberModeKeymap;
}
注意,要使编辑框正常显示,记得更改container的CountComponentControls和ComponentControl函数,正确处理控件数目和编辑框指针。另外,要使编辑框能正常接收按键事件,要显示调用编辑框的OfferKeyEventL函数,如下:
Code:
TKeyResponse CMobileGuardSetKeyContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
return iGKeyEd->OfferKeyEventL( aKeyEvent, aType );
}
更多精彩
赞助商链接