自己动手做Dialog Symbian
来源:互联网 发布:中信建投 mac 编辑:程序博客网 时间:2024/05/16 18:05
<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}a:link, span.MsoHyperlink{color:blue;text-decoration:underline;text-underline:single;}a:visited, span.MsoHyperlinkFollowed{color:purple;text-decoration:underline;text-underline:single;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:595.3pt 841.9pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:42.55pt;mso-footer-margin:49.6pt;mso-paper-source:0;layout-grid:15.6pt;}div.Section1{page:Section1;}-->
一直以来就是在看Examp,今天自己动手写自己的第一个空间,初学者可以和我一起学习,及我遇到的问题,帮助我们一起进步。
打算做一个Example中的对话框输入控件,并把输入显示在手机背景上,好了,直接进入正题。
1 定义资源
我们在默认的工程中 .rss文件下的RESOURCE MENU_PANEr_menu 中,定义一个自己的MENU_ITEM,参考已有的形式,相信不难解决,定义好后,在inc目录下添加自己定义的按钮ID,并在.rls文件中初始化自己定义按键名称(显示用的,相当于Button上的文字)
之后再就来定义我做的Dialog的资源,关于资源中的参数的解释我在前面已经说过,这里就不详细说明,代码如下:
RESOURCE DIALOGr_dialog_text_edit_query
{
flags = EGeneralQueryFlags;
buttons = R_AVKON_SOFTKEYS_OK_CANCEL;
items =
{
DLG_LINE
{
type = EAknCtQuery;
id = EGeneralQuery;
control = AVKON_DATA_QUERY
{
layout = EDataLayout;
label = "INPUT";
control = EDWIN
{
width = 32;
maxlength = 32;
lines = 1;
};
};
}
};
}
2 定义好资源,我们就可以建立我们这个控件的类,我们分成类头和类体来实现,符合Symbian的体系。
定义类头:
首先要定义这个头的宏,千万不要忘了在最后加上 #endif
#ifndef MYEDITORDIALOG_H
#define MYEDITORDIALOG_H
……
#endif
之后可以参看Example的HelloWorld来定义
#include <aknquerydialog.h>
#include <eikbctrl.h>
class CMyEditorDialog : public CAknTextQueryDialog
{
public:
CMyEditorDialog(TDes& aBuf, HBufC *aDefInput);
virtual ~CMyEditorDialog(){};
private:
void PreLayoutDynInitL();
private :
HBufC & iDefInput;
};
开始接触c++的朋友千万不要忘记在类的后面加 “;”,这个类头不难理解,唯一需要解释的是PreLayoutDynInitL();
查看SDK得到如下解释:
From CEikdialog This function iscalled by the EIKON dialog framework just before the dialog is activated, afterit has called PreLayoutDynInitL()and the dialog has been sized.
说明对话框活动的时候,需要这个函数才能设定好大小。(希望我不要翻译错误,英语很烂!)
实现类体
需要包含的库
#include <avkon.hrh>//这个我测试下,发现似乎没有作用,是个系统的资源类
#include "MyEditorDialog.h"
同样可以参看HW代码原型,对构造函数默认初始化
CMyEditorDialog::CMyEditorDialog(TDes& aBuf, HBufC *aDefInput)
: CAknTextQueryDialog( aBuf )//注意这里很关键
, iDefInput(*aDefInput)
{}
还要实现PreLayoutDynInitL()
void CMyEditorDialog::PreLayoutDynInitL()
{
// first we have to executePreLayoutDynInitL() of the base-class
CAknTextQueryDialog::PreLayoutDynInitL();
// acquire pointer to editor-control and set the defaultinput.
CAknQueryControl* control = QueryControl();
control->SetTextL(iDefInput);
// enable OK-button, so that default text can be acceptedas it is
// without modifying the text
MakeLeftSoftkeyVisible( ETrue );
}
3 类的调用
由于UI要调用View ,所以我们先打好View的基础,在View的类头中添加
public:
TDes& GetText(); 这个用来获得我们在Dialog的输入,返回是引用
private:
const CFont* iFont; //字体
TBuf<24> iText; //内容
实现GetText()
TDes& CMyEditorAppView::GetText()
{
return iText;
}
更改ConstructL 设置字体
void CMyEditorAppView::ConstructL(const TRect& aRect)
{
// Create a window for this applicationview
CreateWindowL();
iFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont);//这里用到头#include <aknutils.h>
iText.Zero(); //清0
// Set the windows size
SetRect(aRect);
// Activate the window, which makes itready to be drawn
ActivateL();
}
主要是Draw这个函数
void CMyEditorAppView::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::EDotDashPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
// Gets the control's extent
TRect drawRect(Rect());
// Clears the screen
if (iText.Length() > 0)
{
gc.UseFont(iFont);
gc.DrawText(iText, drawRect, Rect().Height()/3, CGraphicsContext::ECenter );
gc.DiscardFont();
}
else
{
gc.Clear(drawRect);
}
}
不过也很轻松的过去了,到此View的基础都已经打好。接下来就要在调用这个函数。
4 在UI的 void CMyEditorAppUi::HandleCommandL(TInt aCommand)
添加一个自己按钮的Case
case ECommand3:
{
HBufC* defaultText = StringLoader::LoadLC(R_FILE_TEXT);
CMyEditorDialog* dlg = new (ELeave) CMyEditorDialog(iAppView->GetText(), defaultText);//
dlg->ExecuteLD(R_DIALOG_TEXT_EDIT_QUERY);
CleanupStack::PopAndDestroy( defaultText );
}
break;
这些都没难度,关键是dlg->ExecuteLD(R_DIALOG_TEXT_EDIT_QUERY);自己在断点Debug的时候发现执行语句后iText的值就会得到,但是Symbian不让我们自己处理因为我们在new的时候第一个参数执行CAknTextQueryDialog( aBuf ),一个系统函数,查看SDK发现没有太多解释,网上也没查到满意的,还有就是SDK中的构造函数是2个参数的,可是现在我调用的是一个,这个问题我也没有解决,希望高手留下个说法。不胜感激
接下来就可以调试测试自己的对不对,不过最好是每次写一个模块都要测试下,调试会发现出现一大堆错误,原因是程序没问题,可是在DLL链接的时候只有头是没有办法运行的,你还必须要告诉编译器,你还要用到什么类,我觉得j2me的时候有没这些情况,鄙视Symbian,好了,添加的方法是在MMp文件中 自己查看SDK,找到要添加的Lib就可以运行了,祝大家搞定
博文完 宝杰文 有误请斧正
- 自己动手做Dialog Symbian
- 自定义dialog--symbian
- 自己动手做按钮
- 自己动手做按钮 [转]
- 自己动手做网线
- 自己动手做QQ-特洛伊
- hoho,自己动手做图片
- 自己动手做按钮
- 自己动手做WEB控件
- 自己动手做input子系统
- 自己动手做柚子茶
- 自己动手 做rpg小游戏
- 自己动手做推送
- 自己动手做推送
- 自己动手做文件系统
- 自己动手做sidebar
- 自己动手做网线
- 自己动手做推送
- note of HuaWei
- 如何通过HOOK改变windows的API函数
- 海量数据处理---题目
- 企业级的业务系统与互联网应用
- XP下完全卸载Oracle 10g
- 自己动手做Dialog Symbian
- 对于HOOK函数的一点认识
- FTP客户端:FTP Client:win32 console appplication
- Brew上的应用开发
- 快速使用locate命令查找Linux中的文件
- SIM Toolkit开发
- 走走
- js获取HTML DOM节点元素方法总结
- CSS浏览器兼容性