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

📄 sms.c

📁 brew平台下的sms编程1
💻 C
📖 第 1 页 / 共 2 页
字号:

      case EVT_APP_STOP:
		   // Add your code here .....
         return FALSE;

      case EVT_KEY:
         if(wParam == AVK_CLR)
         {
            //close app
            ISHELL_CloseApplet(pApp->a.m_pIShell, FALSE);
            return TRUE;
         }
         else if(wParam == AVK_SELECT)
         {
            if(pApp->m_focus == PHONE_NUMBER_TEXT_CTL)
			{
				pApp->m_focus=SOFTKEY_OK_CTL;
				IMENUCTL_SetActive(pApp->m_pSoftKey, TRUE);
				ITEXTCTL_SetActive(pApp->m_pText, FALSE);
			
			}      
		

         }
         break;

      
      case EVT_COMMAND:
         
		 if(pApp->m_focus == SOFTKEY_OK_CTL)
		 {
			   CurSel = IMENUCTL_GetSel(pApp->m_pSoftKey);
                if(CurSel == IDS_OK)
				{
                  pApp->m_focus= MESSAGE_TEXT_CTL;
				
				  TextMesage_init(pApp);
				  IMENUCTL_SetActive(pApp->m_pMessageSoftKey, FALSE);
				  ITEXTCTL_SetActive(pApp->m_pMessageText, TRUE);				
				}
				else
				{
                    ISHELL_CloseApplet(pApp->a.m_pIShell, FALSE);
                    return TRUE;
                    
				}
		 }
		 		
         else if(pApp->m_focus == MESSAGE_TEXT_CTL) //send sms
         {
            
               CurSel=IMENUCTL_GetSel(pApp->m_pMessageSoftKey);

               if(CurSel==IDS_RETURN)
               {
                  ISHELL_CloseApplet(pApp->a.m_pIShell, FALSE);
                  return TRUE;
               }
			   else if(CurSel == IDS_SEND_SMS)
			   {
                 //send sms
				 IMENUCTL_SetActive(pApp->m_pMessageSoftKey, FALSE);
				 ITEXTCTL_SetActive(pApp->m_pMessageText, FALSE);
                 sms_Send(pApp);
				 pApp->m_focus = SEND_RESULT_CTL;
               }
          }

		 else if(pApp->m_focus == SEND_RESULT_CTL)
		 {
            // return to the initial state, begin to send another sms 
			 sms_release(pApp);
             sms_InitAppData(pApp);
			 sms_init(pApp);
             IMENUCTL_SetActive(pApp->m_pSoftKey, FALSE);
		     ITEXTCTL_SetActive(pApp->m_pText, TRUE);
      	      return(TRUE);
			 			 
		 }

         return TRUE;

	 case EVT_APP_SUSPEND:
         
      IMENUCTL_SetActive(pApp->m_pMessageSoftKey, FALSE);
	  DBGPRINTF("Received EVT_APP_SUSPEND Message!");
	      return TRUE;

      case EVT_APP_RESUME:
	    DBGPRINTF("Received EVT_APP_RESUME Message!");
		  return TRUE;

	  
	  case EVT_USER:
         
      if(wParam == SUCCESS)
      {
		 ISTATIC_SetActive(pApp->m_pStatic, FALSE);
		 ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_RESULT, szTitle, 20);
	     ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_SUCCESS, szText, 20);
	     ISTATIC_SetText(pApp->m_pStatic,szTitle,szText,AEE_FONT_BOLD, AEE_FONT_NORMAL);
	     ISTATIC_SetActive(pApp->m_pStatic, TRUE);
		 IMENUCTL_AddItem(pApp->m_pResultSoftKey, SMS_RES_FILE, IDS_BACK, IDS_BACK, NULL, NULL);
	     IMENUCTL_SetActive(pApp->m_pResultSoftKey,TRUE);
		  

         
      }
      else
      {
		 ISTATIC_SetActive(pApp->m_pStatic, FALSE);
		 ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_RESULT, szTitle, 20);
	     ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_FAIL, szText, 20);
	     ISTATIC_SetText(pApp->m_pStatic,szTitle,szText,AEE_FONT_BOLD, AEE_FONT_NORMAL);
	     ISTATIC_SetActive(pApp->m_pStatic, TRUE);

		 IMENUCTL_AddItem(pApp->m_pResultSoftKey, SMS_RES_FILE, IDS_BACK, IDS_BACK, NULL, NULL);
	     IMENUCTL_SetActive(pApp->m_pResultSoftKey,TRUE);
		 
         
      }
      

         return TRUE;

     
      default:
         break;
   }
   return FALSE;
}


static void sms_init(CSmsApp * pApp)
{
   AEERect rect;
    

   //0. Create Main Info controls according to page
   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_TEXTCTL, (void**)(&pApp->m_pText))!=SUCCESS)
   {
      pApp->m_pText = NULL;
      return;
   }
   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_SOFTKEYCTL, (void**)(&pApp->m_pSoftKey))!=SUCCESS)
   {
      pApp->m_pSoftKey = NULL;
      return;
   }

   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_TAPI, (void**)(&pApp->m_pITAPI))!=SUCCESS)
   {
      pApp->m_pITAPI = NULL;
      return;
   }

    

   IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
  
   SETAEERECT(&rect, 0, 0, pApp->m_rc.dx, pApp->m_fontHeight*3);
   

   // Set title of Text Control of Phone number
   ITEXTCTL_SetTitle(pApp->m_pText, SMS_RES_FILE, IDS_PHONE_NUMBER, NULL);

   // Set maximum text size supported by the text control object
   ITEXTCTL_SetMaxSize(pApp->m_pText, PHONE_NUM);

   // Set properties to have thetext control object have a
   // frame and to have a multi-line text edit space.
   ITEXTCTL_SetProperties(pApp->m_pText,  TP_FRAME|TP_MULTILINE);
   ITEXTCTL_SetRect(pApp->m_pText, &rect);

   // Set the initial text of the text control object.
 
   if (ISHELL_GetPrefs(pApp->a.m_pIShell, AEECLSID_SMS, SMS_PREFS_VERSION,
						   &pApp->m_Prefs, sizeof(pApp->m_Prefs)) != SUCCESS)
   {
		   MEMSET(&pApp->m_Prefs, 0, sizeof(pApp->m_Prefs));
   }   
   STRCPY(pApp->strNum, pApp->m_Prefs.phoneNum);
   

   STRTOWSTR(pApp->strNum, pApp->wStrNum, sizeof(pApp->wStrNum));
   ITEXTCTL_SetText(pApp->m_pText, pApp->wStrNum, sizeof(pApp->wStrNum));


   ITEXTCTL_SetInputMode(pApp->m_pText, AEE_TM_NUMBERS);
    
   //set softkey
   IMENUCTL_AddItem(pApp->m_pSoftKey, SMS_RES_FILE, IDS_OK, IDS_OK, NULL, NULL);
   IMENUCTL_AddItem(pApp->m_pSoftKey, SMS_RES_FILE, IDS_RETURN, IDS_RETURN, NULL, NULL);
     
  
   IMENUCTL_Redraw(pApp->m_pSoftKey);

   IDISPLAY_UpdateEx(pApp->a.m_pIDisplay, TRUE);
   pApp->m_focus = PHONE_NUMBER_TEXT_CTL;
    
}


static void TextMesage_init(CSmsApp * pApp)
{
    AEERect rect;
    
  
   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_TEXTCTL, (void**)(&pApp->m_pMessageText))!=SUCCESS)
   {
      pApp->m_pMessageText = NULL;
      return;
   }

   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_SOFTKEYCTL, (void**)(&pApp->m_pMessageSoftKey))!=SUCCESS)
   {
      pApp->m_pMessageSoftKey = NULL;
      return;
   }


   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_STATIC, (void**)(&pApp->m_pStatic))!=SUCCESS)
   {
      pApp->m_pStatic = NULL;
      return;
   }
  
   if(ISHELL_CreateInstance(pApp->a.m_pIShell, AEECLSID_SOFTKEYCTL, (void**)(&pApp->m_pResultSoftKey))!=SUCCESS)
   {
      pApp->m_pResultSoftKey = NULL;
      return;
   }

   //IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
  
   SETAEERECT(&rect, 0, 0, pApp->m_rc.dx, pApp->m_fontHeight*4 );
   

   // Set title of Message Text Box Control
   ITEXTCTL_SetTitle(pApp->m_pMessageText, SMS_RES_FILE, IDS_MESSAGE_TEXT, NULL);
   // Set maximum text size supported by the text control object
   ITEXTCTL_SetMaxSize(pApp->m_pMessageText, 100);

   // Set properties to have thetext control object have a
   // frame and to have a multi-line text edit space.
   ITEXTCTL_SetProperties(pApp->m_pMessageText,  TP_FRAME | TP_MULTILINE);
   
   ITEXTCTL_SetRect(pApp->m_pMessageText, &rect);
    
   ITEXTCTL_SetSoftKeyMenu(pApp->m_pMessageText, pApp->m_pMessageSoftKey);

   ITEXTCTL_SetInputMode(pApp->m_pMessageText, AEE_TM_FIRST_OEM+1);

   ITEXTCTL_SetActive (pApp->m_pMessageText, TRUE);

      
   IMENUCTL_AddItem(pApp->m_pMessageSoftKey, SMS_RES_FILE, IDS_SEND_SMS, IDS_SEND_SMS, NULL, NULL);
   IMENUCTL_AddItem(pApp->m_pMessageSoftKey, SMS_RES_FILE, IDS_RETURN, IDS_RETURN, NULL, NULL);
    
   IMENUCTL_Redraw(pApp->m_pMessageSoftKey);
   

   // set static control
   SETAEERECT(&rect, 0, 0, pApp->m_rc.dx, pApp->m_fontHeight*6 );
   ISTATIC_SetRect(pApp->m_pStatic, &rect);
   ISTATIC_SetProperties(pApp->m_pStatic,  ST_CENTERTEXT|ST_MIDDLETEXT);

}


static void sms_Send(CSmsApp * pApp)
{
   int16 ReturnValue;
   AECHAR szTitle[20];
   AECHAR szText[20];
   AECHAR wBrewHeader[64];
   char   BrewHeader[64];
   int TextBodyBegin = 0;


   if(pApp->m_pITAPI == NULL)
      return;

   //get phone number
   ITEXTCTL_GetText(pApp->m_pText, pApp->wStrNum, PHONE_NUM);
   WSTRTOSTR(pApp->wStrNum, pApp->strNum, sizeof(pApp->strNum));

   //save phone number
   STRCPY(pApp->m_Prefs.phoneNum, pApp->strNum);
   ISHELL_SetPrefs(pApp->a.m_pIShell, AEECLSID_SMS, SMS_PREFS_VERSION,
				&pApp->m_Prefs, sizeof(pApp->m_Prefs));

   //get text message 

   // load the message header   //BREW:0x01009FF0:
   ISHELL_LoadResString(pApp->a.m_pIShell,SMS_RES_FILE,IDS_BREW_MSG_HEADER, wBrewHeader,20*2);
   WSTRTOSTR(wBrewHeader, BrewHeader,20);

   //Add to the message text
   STRNCPY( (char *)(pApp->wStrMessage), BrewHeader, sizeof(BrewHeader) );

   TextBodyBegin = STRLEN(BrewHeader)/2;

   ITEXTCTL_GetText(pApp->m_pMessageText, &(pApp->wStrMessage[TextBodyBegin]), MESSAGE_LENGTH);
  
   

	
	// send message
	ReturnValue = ITAPI_SendSMS(pApp->m_pITAPI, (const char *)pApp->strNum,  (const char *)pApp->wStrMessage,
    		0, (PFNSMSSTATUS)MySmsNotify, pApp);
    
	IDISPLAY_ClearScreen(pApp->a.m_pIDisplay);
	if(ReturnValue == SUCCESS)
	{
      
	  ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_RESULT, szTitle, 20);
	  ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SENDING, szText, 20);
	  ISTATIC_SetText(pApp->m_pStatic,szTitle,szText,AEE_FONT_BOLD, AEE_FONT_NORMAL);
	  ISTATIC_SetActive(pApp->m_pStatic, TRUE);
	 

	}
	else
	{
        
	  ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_RESULT, szTitle, 20);
	  ISHELL_LoadResString(pApp->a.m_pIShell, SMS_RES_FILE, IDS_SEND_FAIL, szText, 20);
	  ISTATIC_SetText(pApp->m_pStatic,szTitle,szText,AEE_FONT_BOLD, AEE_FONT_NORMAL);
	  ISTATIC_SetActive(pApp->m_pStatic, TRUE);

	  IMENUCTL_AddItem(pApp->m_pResultSoftKey, SMS_RES_FILE, IDS_BACK, IDS_BACK, NULL, NULL);
	  IMENUCTL_SetActive(pApp->m_pResultSoftKey,TRUE);
	  
      
	}
	

}

static void MySmsNotify(CSmsApp * pApp, int16 status)
{
   
  pApp->SentStatus = status;

  ISHELL_PostEvent (pApp->a.m_pIShell, AEECLSID_SMS, 
               EVT_USER, status, 0);

   DBGPRINTF("Message send notify(%d)!",status);
}

⌨️ 快捷键说明

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