1、在.h文件中加入相关的头文件
#include // for CAknEnv::Static()
#include //for CAknIndicatorContainer
2、在.h文件中加入用到的类定义
struct S_uid: public TUid
{
S_uid(int i)
{
iUid = i;
}
};
class MAknEditingStateIndicator
{
public:
virtual void SetState(TAknEditingState aState) = 0;
virtual CAknIndicatorContainer *IndicatorContainer() = 0;
};
在系统的头文件(C:Symbian7.0sSeries60_v20Epoc32includeaknenv.h )中类CAknEnv用到了类MAknEditingStateIndicator,但SDK中没有提供这个类定义,所以要在这里加上。
3、在.cpp文件中实现
void TestInputMethod()
{
MAknEditingStateIndicator * ei = CAknEnv::Static()->EditingStateIndicator() ;
if (!ei) return;
CAknIndicatorContainer *ic = ei->IndicatorContainer();
if (!ic) return;
if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorT9) ))
{
//to do ... if input method = T9 (即拼音和笔画)
}
else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorLowerCase)))
{
//to do ... if input method = "abc";
}
else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorUpperCase)))
{
//to do ... if input method = "ABC";
}
else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorTextCase)))
{
//to do ... if input method = "Abc";
}
else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorNumberCase)))
{
//to do ... if input method = "123";
}
}
用这种方法,当前的输入法是拼音和笔画时,IndicatorState(S_uid(EAknNaviPaneEditorIndicatorT9) )都为TRUE,因为输入法的切换是按一定的顺序的,所以可以考虑用顺序来进一步判断这两种输入法。
在SDK中的目录C:Symbian7.0sSeries60_v20Epoc32includeavkon.hrh(或C:Symbian8.0aS60_2nd_FP2_SCepoc32includeavkon.hrh)中定义上面用到的一些枚举值。
// Navi pane editor indicators
EAknNaviPaneEditorIndicatorT9 = 100,
EAknNaviPaneEditorIndicatorUpperCase,
EAknNaviPaneEditorIndicatorLowerCase,
EAknNaviPaneEditorIndicatorTextCase,
EAknNaviPaneEditorIndicatorNumberCase,
EAknNaviPaneEditorIndicatorQuery,
EAknNaviPaneEditorIndicatorQwertyShift,
EAknNaviPaneEditorIndicatorArabicCase = 130,
EAknNaviPaneEditorIndicatorHebrewCase,
EAknNaviPaneEditorIndicatorArabicIndicNumberCase,
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-126319/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-126319/