⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 《深入brew开发》——第七章 创建新的brew应用程序 - gemsea的专栏 - csdnblog.htm

📁 《深入BREW开发》——第八章 BREW的事件处理
💻 HTM
📖 第 1 页 / 共 5 页
字号:
            <DIV>PARAMETERS:</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pi: Pointer to the 
            AEEApplet structure. This structure contains information 
            specific</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; to this applet. It 
            was initialized during the AEEClsCreateInstance() 
            function.</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ecode: Specifies the 
            Event sent to this applet</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp; wParam, dwParam: Event specific 
            data.</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV>DEPENDENCIES</DIV>
            <DIV>&nbsp;none</DIV>
            <DIV>&nbsp;</DIV>
            <DIV>RETURN VALUE</DIV>
            <DIV>&nbsp;TRUE: If the app has processed the event</DIV>
            <DIV>&nbsp;FALSE: If the app did not process the event</DIV>
            <DIV>&nbsp;</DIV>
            <DIV>SIDE EFFECTS</DIV>
            <DIV>&nbsp;none</DIV>
            <DIV>====================================================================*/</DIV>
            <DIV>static boolean helloworld_HandleEvent(helloworld* pMe, AEEEvent 
            eCode, uint16 wParam, uint32 dwParam)</DIV>
            <DIV>{&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AECHAR szBuf[] = 
            {'H','e','l','l','o',' ',</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'W','o','r','l','d','\0'};</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; switch (eCode) </SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // App is told 
            it is starting up</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 
            EVT_APP_START:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp; // Add your code here...</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // Clear the display.</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            IDISPLAY_ClearScreen( pMe-&gt;a.m_pIDisplay );</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // Display string on the screen</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            IDISPLAY_DrawText( pMe-&gt;a.m_pIDisplay, // What</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp; 
            AEE_FONT_BOLD,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // What font</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp; 
            szBuf,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // How many chars</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp; -1, 0, 0, 
            0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // Where &amp; clip</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp; IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE );</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // Redraw the display to show the drawn text</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            IDISPLAY_Update (pMe-&gt;a.m_pIDisplay);</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            return(TRUE);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // App is told 
            it is exiting</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 
            EVT_APP_STOP:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            // Add your code here...</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            return(TRUE);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;// App is 
            being suspended </SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 
            EVT_APP_SUSPEND:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp; // Add your code here...</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            return(TRUE);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // App is 
            being resumed</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 
            EVT_APP_RESUME:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp; // Add your code here...</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            return(TRUE);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // A key was 
            pressed. Look at the wParam above to see which key was pressed. The 
            key</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // codes are 
            in AEEVCodes.h. Example "AVK_1" means that the "1" key was 
            pressed.</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 
            EVT_KEY:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp; // Add your code here...</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            return(TRUE);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // If nothing 
            fits up to this point then we'll just break out</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            default:</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
            break;</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp; }</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp; return FALSE;</SPAN></DIV>
            <DIV>}</DIV>
            <DIV>&nbsp;</DIV>
            <DIV>// this function is called when your application is starting 
            up</DIV>
            <DIV>boolean helloworld_InitAppData(helloworld* pMe)</DIV>
            <DIV>{</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // Get the device information for this 
            handset.</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // Reference all the data by looking 
            at the pMe-&gt;DeviceInfo structure</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // Check the API reference guide for 
            all the handy device info you can get</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; pMe-&gt;DeviceInfo.wStructSize = 
            sizeof(pMe-&gt;DeviceInfo);</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; 
            ISHELL_GetDeviceInfo(pMe-&gt;a.m_pIShell,&amp;pMe-&gt;DeviceInfo);</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // Insert your code here for 
            initializing or allocating resources...</SPAN></DIV>
            <DIV>&nbsp;</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // if there have been no failures up 
            to this point then return success</SPAN></DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; return TRUE;</SPAN></DIV>
            <DIV>}</DIV>
            <DIV>&nbsp;</DIV>
            <DIV>// this function is called when your application is 
            exiting</DIV>
            <DIV>void helloworld_FreeAppData(helloworld* pMe)</DIV>
            <DIV>{</DIV>
            <DIV><SPAN>&nbsp;&nbsp;&nbsp; // insert your code here for freeing 
            any resources you have allocated...</SPAN></DIV>
            <DIV>}</DIV></TD></TR></TBODY></TABLE>
      <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </SPAN>这个文件当中的代码大部分是经过BREW向导产生的,为了方便排版,我对里面的代码进行了一些小改动。由于这是第一次展示BREW应用程序,因此保留了向导生成的注释等内容,目的是让您能够看到BREW应用的全貌。今后的应用程序展示,将只使用骨干程序,以节省版面空间并减少对您钱财的浪费。</DIV>
      <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </SPAN>正如前面我们所见的,在这个文件中共有四个BREW骨干函数存在,它们分别是:AEEClsCreateInstance、helloworld_HandleEvent、helloworld_InitAppData以及helloworld_FreeAppData。它们在整个BREW应用程序中扮演着不同的角色,而且AEEClsCreateInstance和***_HandleEvent函数还是每一个动态应用程序必不可少的。接下来让我们来看看它们各自的作用以及相互之间的关系。</DIV>
      <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      AEEClsCreateInstance(AEECLSID ClsId, IShell *pIShell, IModule *po, void 
      **ppObj)</SPAN>函数是整个BREW应用程序的一个入口点,在其内部调用了AEEApplet_New函数用来创建应用程序实例。AEEApplet_New函数在AEEAppGen.c文件中,这个函数可以指定一个事件处理函数和一个资源释放函数,在这个程序中指定的分别是helloworld_HandleEvent和helloworld_FreeAppData函数。在AEEClsCreateInstance函数中将几个重要的参数传进了BREW应用程序中,如IShell指针pIShell、要创建的Class 
      ID 
      ClsId、模块指针po以及应用程序实例返回指针ppObj等。我们还可以看到在AEEApplet_New函数调用成功后,将执行helloworld_InitAppData函数,用来初始化数据,这就是这个初始化函数得到执行的地方。</DIV>
      <DIV><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      </SPAN>在helloworld.c文件中,还定义了一个helloworld结构体。由于BREW实现原理上的特点,这个结构体就成为了BREW应用程序存储全局变量的地方。如果我们需要在我们的应用程序运行期间保存数据,请在这个结构体中增加变量,而不要使用全局函数。在运行时,AEEApplet_New函数会根据这个结构体的大小分配存储空间。这个结构体中默认声明的第一个变量是AEEApplet结构,这个声明的顺序不可以改变。AEEApplet的定义如下(参考AEEAppGen.h文件):</DIV>
      <TABLE 
      style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" 
      cellSpacing=0 cellPadding=0 border=1>
        <TBODY>
        <TR>
          <TD 
          style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid" 
          vAlign=top width=568>
            <DIV>struct _AEEApplet</DIV>
            <DIV>{</DIV>
            <DIV><SPAN>&nbsp;&nbsp; // </SPAN></DIV>
            <DIV><

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -