Symbian 第一个APP

<!-- /* 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;} p {mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

/*
 ============================================================================
 Name        : Symbian
基于carbide c++ 的第一个窗口建立
 Author      :
宝杰
 Copyright   : Your copyright notice
 Description :
默认工程下 自己建立一个按钮 并显示String
 ============================================================================
 */

 

  经过前几天的学习,相信大家和我一样,可以看懂基本的Symbian C++ , 可是程序是要自己调试的,这里我们就一起来调试第一个自己的程序

 

  1. 建立默认工程

  2. 打开INc 目录下的first.hrh 文件 (这是一个资源的头文件)

     如下

#ifndef __FIRST_HRH__

#define __FIRST_HRH__

 

#define _UID3 0xE632A065

 

// first enumerate command codes

enum TfirstIds

    {

    ECommand1 = 0x6001, // start value must not be 0

    ECommand2 ,

    EChange ,

    EHelp ,

    EAbout

    };

 

#endif // __FIRST_HRH__

    我在这里添加了 EChange, 命名遵循要求是个好习惯。

 3. 打开 data 目录下的 first.rls 文件 自己查看注释 A .rls file is the one and only place where the logical
                strings to be localised are defined.

/*

============================================================================

 Name      : first.rls

 Author   :

 Copyright   : Your copyright notice

 Description : This is a localisation file for first

              A .rls file is the one and only place where the logical

              strings to be localised are defined.

============================================================================

*/

 

//  LOCALISATION STRINGS

 

// Caption string for app.

#define qtn_caption_string "first"

 

// First item in "Options" menu pane

#define qtn_command1 "Message"

 

// Second item in "Options" menu pane

#define qtn_command2 "Message from file"

 

#define qtn_change "Change the dectobin"

#define qtn_help "Help"

 

#define qtn_about "About"

 

// Third item in "Options" menu pane

#define qtn_exit "Exit"

 

// When user requests ECommand1 event, text below is shown.

#define qtn_command1_text "Hello World!"

 

#define qtn_change_text "Hello QianXuJie!"

 

#define qtn_loc_resource_file_1 "//resource//apps//first_0xE632A065"

 

#define qtn_about_dialog_title "Qianxujie D"

 

#define qtn_about_dialog_text "first Version 1.0.0/n/nAuthor: /n/nSupport: support@mycompany.com/n/n(c) Your copyright notice"

 

// End of File

  这样我们的常量都已经定义好了,然后我们要把这个按钮添加到菜单的资源中;

  4. 我们打开 Data 目录下的 first.rss 文件,这个是资源定义的最重要文件(我老大告诉我的)

     我们看到很多的 RESOURCE 找到 RESOURCE MENU_PANE r_menu 如下:

// -----------------------------------------------------------------------------

//

//   r_menu

//   Menu for "Options"

//

// -----------------------------------------------------------------------------

//

RESOURCE MENU_PANE r_menu

    {

    items =

       {

       // added the new Options menu command here

       MENU_ITEM

              {

              command = ECommand1;

              txt = qtn_command1 ;

              },

       MENU_ITEM

              {

              command = ECommand2;

              txt = qtn_command2 ;

              },

       MENU_ITEM

              {

              command = EChange;

              txt = qtn_change ;

              },

       MENU_ITEM

              {

              command = EHelp;

              txt = qtn_help ;

              },

       MENU_ITEM

              {

              command = EAbout;

              txt = qtn_about ;

              },

       MENU_ITEM

              {

              command = EAknSoftkeyExit;

              txt = qtn_exit ;

              }

       };

    }

  看注释我们知道这个是 Option 的菜单,正是我们手机常用的左键开始,我在里面添加了红色字体段,成为一个 Item ,至于这个结构的话,前门我在别处已经说过,当然你如果要查看这些方法,请自己翻看SDK帮助文档;

  到此,如果你运行下代码会发现有了这个菜单,由于没发上传图片,我就不贴了;

  5. 那么我们怎么处理这个按钮呢?在 J2me 中,我们用 CommendListener 来监控,在 Symbian 中,我们在

Src/firstAppUi 找到

// -----------------------------------------------------------------------------

// CfirstAppUi::HandleCommandL()

// Takes care of command handling.

// 这个是所有的按钮响应   看的比较累

// -----------------------------------------------------------------------------

//

void CfirstAppUi::HandleCommandL ( TInt aCommand)

    {

    switch (aCommand)

       {

       case EEikCmdExit :

       case EAknSoftkeyExit :

           Exit ();

           break ;

 

       case ECommand1 :

           {

 

           // Load a string from the resource file and display it

           HBufC * textResource = StringLoader :: LoadLC ( R_COMMAND1_TEXT );

           CAknInformationNote * informationNote;

 

           informationNote = new ( ELeave ) CAknInformationNote ;

 

           // Show the information Note with

           // textResource loaded with StringLoader.

           informationNote-> ExecuteLD (*textResource);

 

           // Pop HBuf from CleanUpStack and Destroy it.

           CleanupStack :: PopAndDestroy (textResource);

           }

           break ;

       case ECommand2 :

           {

           RFile rFile;

 

           //Open file where the stream text is

           User :: LeaveIfError (rFile. Open ( CCoeEnv :: Static ()-> FsSession (),

                  KFileName, EFileStreamText )); //EFileShareReadersOnly));// EFileStreamText));

           CleanupClosePushL(rFile);

 

           // copy stream from file to RFileStream object

           RFileReadStream inputFileStream(rFile);

           CleanupClosePushL(inputFileStream);

 

           // HBufC descriptor is created from the RFileStream object.

           HBufC * fileData = HBufC :: NewLC (inputFileStream, 32);

 

           CAknInformationNote * informationNote;

 

           informationNote = new ( ELeave ) CAknInformationNote ;

           // Show the information Note

           informationNote-> ExecuteLD (*fileData);

 

           // Pop loaded resources from the cleanup stack

           CleanupStack :: PopAndDestroy (3);

           // filedata, inputFileStream, rFile 这里这个数字 3 代表文件 , 是把之前的栈都空

          

           }

           break ;

       case EChange :

           {

           // Load a string from the resource file and display it

           HBufC* textResource = StringLoader::LoadLC (R_CHANGE_TEXT );

           CAknInformationNote* informationNote;

 

           informationNote = new (ELeave ) CAknInformationNote ;

 

           // Show the information Note with

           // textResource loaded with StringLoader.

           informationNote->ExecuteLD (*textResource);

 

           // Pop HBuf from CleanUpStack and Destroy it.

           CleanupStack::PopAndDestroy (textResource);

           break ;

           }

       case EHelp :

           {

 

           CArrayFix < TCoeHelpContext >* buf = CCoeAppUi :: AppHelpContextL ();

           HlpLauncher :: LaunchHelpApplicationL ( iEikonEnv -> WsSession (), buf);

           }

           break ;

       case EAbout :

           {

 

           CAknMessageQueryDialog * dlg = new ( ELeave ) CAknMessageQueryDialog (); // 创建一个对话框

           dlg-> PrepareLC ( R_ABOUT_QUERY_DIALOG ); // 预备对话框,用 R_ABOUT_QUERY_DIALOG 来构造

           HBufC * title = iEikonEnv -> AllocReadResourceLC ( R_ABOUT_DIALOG_TITLE ); // 读出资源数据

           dlg-> QueryHeading ()-> SetTextL (*title); // 把文字写入顶部

           CleanupStack :: PopAndDestroy ();

           //title  由于 R_ABOUT_DIALOG_TITLE 资源的写入用 AllocReadResourceLC

           //Lc 结尾的函数不用显式的 Del ,如果是 L 结尾的话 就要 调用 Delete(title)

           HBufC * msg = iEikonEnv -> AllocReadResourceLC ( R_ABOUT_DIALOG_TEXT );

           dlg-> SetMessageTextL (*msg); // 写入内容

           CleanupStack :: PopAndDestroy (); //msg

           dlg-> RunLD (); // 运行

           }

           break ;

       default :

           Panic( EfirstUi );

           break ;

       }

    }

我添加的红色字体是 Copy ECommand1 的,自己写了一个 Case EChange 但是当你写的时候发现这个 R_CHANGE_TEXT 我们并没有定义,对的,我们还没有把 qtn_change_text R_CHANGE_TEXT 联系起来

  最后我们在 first.rrs 找到

// -----------------------------------------------------------------------------

//

// Resources for messages.

//

// -----------------------------------------------------------------------------

//

RESOURCE TBUF32 r_caption_string { buf= qtn_caption_string ; }

RESOURCE TBUF32 r_about_dialog_title { buf= qtn_about_dialog_title ; }

RESOURCE TBUF r_about_dialog_text { buf= qtn_about_dialog_text ; }

RESOURCE TBUF r_command1_text { buf= qtn_command1_text ; }

RESOURCE TBUF r_change_text { buf= qtn_change_text ; }

定义了最后一行 好了 这样你就可以看自己新建的这个按钮和他的功能了。

博文完 宝杰

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值