//--------------------------------------------------------------获取短字符8位的 汉字拼音------------------------------------------------
TBuf<128> aInfo1(L"KErrNone");
TBuf<128> aInfo2(L"KErrNotSupported");
_LIT8(KStrTest,"郑州");
HBufC* pTest = NHelper::ConvGbk2UniL(KStrTest); //此函数定义在别的文件中,功能是把KStrTest短字符转换为GBK字符
CPtiEngine* aEngine = CPtiEngine::NewL();
aEngine->ActivateLanguageL(ELangPrcChinese);
const TUint16*nUint = pTest->Des().Ptr();
TBuf<128> aOut;
TInt nRet = aEngine->GetSpelling(*nUint, aOut, EPtiPinyin);
if(nRet==KErrNone)
{
CEikonEnv::Static()->InfoWinL( aInfo1, aOut);
}
else if(nRet==KErrNotSupported )
{
CEikonEnv::Static()->InfoWinL( aInfo2, aInfo2 );
}
else
{
CEikonEnv::Static()->InfoWinL( aOut, aOut );
}
if(pTest)
{
delete pTest;
pTest = NULL;
}
aEngine->CloseCurrentLanguageL();
if(aEngine)
{
delete aEngine;
aEngine = NULL;
}
//--------------------------------------------------------获取长字符16位中文的拼音首 写字母------------------------------------------------------
CPtiEngine* aEngine = CPtiEngine::NewL();
aEngine->ActivateLanguageL(ELangPrcChinese);
//一共有多少条记录
TInt nCount = iAllRecord.Count();
for (TInt i = 0; i < nCount; i++)
{
//每条记录的名称有多长
TInt nNameLength = iAllRecord[i]->iName.Length();
for (TInt j = 0; j < nNameLength; j++)
{
TUint16 iInt16 = iAllRecord[i]->iName[j];
TBuf<3> bMid;
bMid.Append(iAllRecord[i]->iName.Mid(j, 1));
//该字符如果是汉字
if ((iInt16 >= 0x4E00) && (iInt16 <= 0x9FA5))
{
HBufC* pTest = HBufC::NewL(6);
pTest->Des().Append(bMid);
const TUint16*nUint = pTest->Des().Ptr();
TBuf<128> aOut;
TInt nRet = aEngine->GetSpelling(*nUint, aOut, EPtiPinyin);
if (nRet == KErrNone)
{
//如果获取了全拼,只截取首拼
if (0 < aOut.Length())
{
iAllRecord[i]->iJianpin.Append(aOut.Mid(0, 1));
}
}
MEM_FREE(pTest);
}
//如果不是汉字,就把本字母追加到简拼中
else
{
iAllRecord[i]->iJianpin.Append(bMid);
}
}
}
aEngine->CloseCurrentLanguageL();
MEM_FREE(aEngine);