×
Namespaces

Variants
Actions

如何为文本编辑框添加标题

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
文章
关键词: CEikEdwin MCoeCaptionRetrieverForFep GetCaptionForFep TCoeInputCapabilities InputCapabilities
翻译:
chenziteng
最后由 hamishwillee 在 22 Dec 2011 编辑

Contents

概述

在S60第五版触摸界面中,如果一个文本编辑框有标题,那么虚拟键盘会在待编辑的文本前显示该标题。例如信息编辑器会在待编辑的消息前显示“信息:”。本文介绍了如何为文本编辑框添加标题。

方案

创建一个新的编辑框类,并实现MCoeCaptionRetrieverForFep接口。

#ifndef __MYEDWIN_H__
#define __MYEDWIN_H__
 
#include <eikedwin.h> // CEikEdwin
 
class CMyEdwin : public CEikEdwin, public MCoeCaptionRetrieverForFep
{
public: // CEikEdwin
TCoeInputCapabilities InputCapabilities() const;
 
public: // MCoeCaptionRetrieverForFep
void GetCaptionForFep(TDes& aCaption) const;
};
 
#endif

重载GetCaptionForFep()方法提供标题,重载InputCapabilities()方法将this指针设置成标题的提供者。

#include "MyEdwin.h"
 
void CMyEdwin::GetCaptionForFep(TDes& aCaption) const
{
_LIT(KCaption, "Caption:");
aCaption = KCaption; // note: in a real world application you should check the capacity of aCaption to avoid "USER 11 Panic"
}
 
TCoeInputCapabilities CMyEdwin::InputCapabilities() const
{
TCoeInputCapabilities caps = CEikEdwin::InputCapabilities();
TCoeInputCapabilities caps2 = TCoeInputCapabilities(TCoeInputCapabilities::ENone, NULL, const_cast<CMyEdwin*>(this));
caps.MergeWith(caps2);
return caps;
}

源代码

下载完整的示例程序 (源代码在S60第五版仿真器上验证通过):

HelloWorld(CaptionedEditor).zip

屏幕截图

为没有标题的编辑框和有标题的编辑框加载的虚拟键盘。

EdwinNoCaption.PNG CaptionedEdwin.PNG

This page was last modified on 22 December 2011, at 08:06.
72 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×