所有移动开发架构中高通Brew可能是最令人感到痛苦的一种通用平台,复杂的API和不禁详尽的文档,使开发者对Brew望而却步。
北京讯岚通过2年的研发实践完成了Brew标准类库BFC,协助BREW开发者爱好者一同步入BREW的神奇移动世界(购买BREW类库项目请来电垂询北京讯岚 TEL:51833115).
本文列举使用BREW标准类库所开发的示例应用个人所得税计算:
#if !defined(AFX_WisdomBFCAPP_H__10531DDA_D9FB_4912_976E_00879ADDE742__INCLUDED_)
#define AFX_WisdomBFCAPP_H__10531DDA_D9FB_4912_976E_00879ADDE742__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "BFC\BFC.h"
#include "BFC\BASE\BFCApp.h"
#include "WisdomBFC_Res.h"
class CWisdomBFCApp : public CBFCApp
{
public:
CWisdomBFCApp(AEEApplet *pAEEApplet);
virtual ~CWisdomBFCApp();
virtual boolean OnStart();
virtual boolean OnStop();
virtual boolean OnSMSMessage(char*pMessage,IShell*pShell) ;
private:
CMedia* mm;
};
#endif
// WisdomBFCApp.cpp: implementation of the CWisdomBFCApp class.
//
//////////////////////////////////////////////////////////////////////
#include "WisdomBFCApp.h"
#include "CalculateWindow.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CWisdomBFCApp::CWisdomBFCApp(AEEApplet *pAEEApplet) : CBFCApp(pAEEApplet){}
CWisdomBFCApp::~CWisdomBFCApp(){}
boolean CWisdomBFCApp::OnStart()
{
mm=new CMedia(this->m_pAEEApplet);
mm->playSoundFile("sky.mid");
//1-欢迎屏幕
SetAppInfo(
(AECHAR *)L"个人所得税计算",
(AECHAR *)L"北京 ☆ QuickLine\nVersion 1.0\nCopyRight 2005",
(AECHAR *)L"src\\logo.png"
);
REFRESHAPPSTRING();
//2-创建所需窗体
CCalculateWindow *pCalculateWindow = new CCalculateWindow(0);
//3-将所创建窗体加入回收列表,便于程序结束后清理
AddTemplateWindow(pCalculateWindow);
//4-设置启始窗体
SetStartupWindow(pCalculateWindow, FALSE);
return TRUE;
}
boolean CWisdomBFCApp::OnStop(){
mm->stopSoundPlay();
delete mm;
return TRUE;
}
boolean CWisdomBFCApp::OnSMSMessage(char*pMessage,IShell*pShell){
return TRUE;
}
#include "BFC\BFC.h"
#include "tips.h"
#pragma once
class CCalculateWindow :
public CBrewWindow
{
public:
CCalculateWindow(uint16 wID);
virtual ~CCalculateWindow(void);
void OnCreate();
boolean OnCommand(uint16 wParam, uint32 dwParam);
boolean OnChildCommand(uint16 wID, uint16 wParam, uint32 dwParam);
boolean HandleEvent(IApplet *pi, AEEEvent eCode, uint16 wParam, uint32 dwParam);
private:
void SetWindowLogo();
//:TODO
public:
//其他特有成员变量
private:
//其他特有成员变量
};
#include ".\calculatewindow.h"
#include "WisdomBFCApp.h"
#include <stdlib.h>
//构造
CCalculateWindow::CCalculateWindow(uint16 wID)
{
AEERect rc;
SETAEERECT(&rc, 0, 0, 0, 0);
CFlatLayout *pLayout = new CFlatLayout(1, 3, 1);
pLayout->AddControl(AddComponent(new CStatic(0)));//城市标题
pLayout->AddControl(AddComponent(new CListCtl(1), TRUE));//城市列表框
pLayout->AddControl(AddComponent(new CStatic(2)));//收入标题
pLayout->AddControl(AddComponent(new CTextCtl(3, rc, TP_FRAME)));//收入文本框
this->RegisterLayoutManager(pLayout);
this->SetTitleBar(TRUE, (AECHAR *)L"个人所得税计算");
this->SetSysCommandBar(TRUE);
}
//析构
CCalculateWindow::~CCalculateWindow(void){}
//初始化
void CCalculateWindow::OnCreate()
{
GetComponent(0)->SetText(/*GETAPPSTRING(IDS_LOGIN_PASSWORD1)*/(AECHAR *)L"您所在的城市");
CListCtl *pCityList = (CListCtl *)GetComponent(1);
pCityList->Reset();
pCityList->AddItem(0, (AECHAR *)L"北京");
pCityList->AddItem(1, (AECHAR *)L"上海");
pCityList->AddItem(2, (AECHAR *)L"深圳");
pCityList->AddItem(3, (AECHAR *)L"其它地区");
GetComponent(2)->SetText((AECHAR *)L"输入您欲计算的收入");
CTextCtl* pTextCtrl=(CTextCtl*)GetComponent(3);
pTextCtrl->SetInputMode(AEE_TM_NUMBERS);
pTextCtrl->setActive();
this->AddSysCommand(0, (AECHAR *)L"计算");
this->AddSysCommand(1, (AECHAR *)L"个人所得税常识");
this->AddSysCommand(2, (AECHAR *)L"退出");
this->SetWindowLogo();
pCityList=NULL;
pTextCtrl=NULL;
}
//获得命令
boolean CCalculateWindow::OnCommand(uint16 wParam, uint32 dwParam)
{
AEEApplet *pAEEApplet = (AEEApplet *)GETAPPINSTANCE();
CMessageBox *pBox;
AECHAR wstrResult[255];
float result=0;//结果
float v1,v2,v3=0;
CTextCtl* pTextCtrl=(CTextCtl*)GetComponent(3);
IMenuCtl *pList = (IMenuCtl *)(((CListCtl *)GetComponent(1))->m_pIControl);
switch (wParam)
{
case 0:
v1=800;
switch(IMENUCTL_GetSel(pList))
{
case 0:
v1=1000;
break;
case 1:
v1=1000;
break;
case 2:
v1=1600;
break;
}
v2 = WSTRTOFLOAT(pTextCtrl->GetText());
v3 = v2 - v1;
if (v3 <= 0) {
v3 = 0;
}
else if (v3 <= 500) {
result=(v3 * 0.05f);
}
else if(v3 <= 2000) {
result=(v3 * 0.1f - 25);
}
else if(v3 <= 5000) {
result=(v3 * 0.15f - 125);
}
else if(v3 <= 20000) {
result=(v3 * 0.2f - 375);
}
else if (v3 <= 40000) {
result=(v3 * 0.25f - 1375);
}
else if (v3 <= 60000) {
result=(v3 * 0.3f - 3375);
}
else if(v3 <= 80000) {
result=(v3 * 0.35f - 6375);
}
else if (v3 <= 100000) {
result=(v3 * 0.4f - 10375);
}
else{
result=(v3 * 0.45f - 15375);
}
result = FADD(result, WSTRTOFLOAT((AECHAR*)L"0.005"));//2位小数舍入+0.005
pBox= new CMessageBox(0, NULL);
if(FLOATTOWSTR(result, wstrResult,4*sizeof(wstrResult)))
{
AECHAR *pbuf = NULL;
AECHAR str1[500]=L"您应缴纳的个人所得税额为:\0";
AECHAR *str2 = NULL;
pbuf = WSTRCHR(wstrResult, (AECHAR)L'.');//取得小数点后第三位字符位置,将其替换为结束符。
if(pbuf)
{
pbuf += 3;
*pbuf = (AECHAR)L'\0';
}
str2=wstrResult;
WSTRCAT(str1,str2);
pBox->Show(this, (AECHAR *)L"计算结果",str1, MB_OK);
}
else
{
pBox->Show(this, (AECHAR *)L"计算错误", (AECHAR*)L"计算中出现错误!", MB_OK);
}
pBox=NULL;
return TRUE;
case 1:
this->NavigateToWindow(new CTips(0));
return TRUE;
case 2:
ISHELL_CloseApplet(pAEEApplet->m_pIShell, FALSE);
return TRUE;
default:
break;
}
return CBrewWindow::OnCommand(wParam, dwParam);
}
//子命令
boolean CCalculateWindow::OnChildCommand(uint16 wID, uint16 wParam, uint32 dwParam)
{
return TRUE;
}
//设置徽标
void CCalculateWindow::SetWindowLogo()
{
BFCApp *app = (BFCApp *)GETAPPINSTANCE();
app->pApp->SetWindowLogo(WISDOMBFC_RES_FILE,RES_IMAGE2_WINDOWSLOGO);
}
//其他事件
boolean CCalculateWindow::HandleEvent(IApplet *pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
boolean bResult;
/*int16 wFocusID = m_wFocusID;*/
bResult = CBrewWindow::HandleEvent(pi, eCode, wParam, dwParam);
/*if (wFocusID == 1 && eCode == EVT_KEY && (wParam == AVK_LEFT || wParam == AVK_RIGHT))
{
//TODO:
}*/
return bResult;
}
#include "BFC\BFC.h"
#pragma once
class CTips :
public CBrewWindow
{
public:
CTips(uint16 wID);
virtual ~CTips(void);
void OnCreate();
boolean OnCommand(uint16 wParam, uint32 dwParam);
boolean OnChildCommand(uint16 wID, uint16 wParam, uint32 dwParam);
boolean HandleEvent(IApplet *pi, AEEEvent eCode, uint16 wParam, uint32 dwParam);
private:
void SetWindowLogo();
//:TODO
public:
//其他特有成员变量
private:
uint16 GetStaticScrollCount();
int16 m_wScrollCount;
};
#include ".\tips.h"
#include "WisdomBFCApp.h"
#include "CalculateWindow.h"
//构造
CTips::CTips(uint16 wID) : CBrewWindow(wID)
{
m_wScrollCount = -1;
AEERect rc;
CGridLayout *pLayout = new CGridLayout(1, 1, 0, 0, 0);
pLayout->AddControl(AddComponent(new CStatic(0)), 0, 0, 1, 1);
RegisterLayoutManager(pLayout);
SetTitleBar(TRUE, (AECHAR *)L"个人所得税常识");
SetSysCommandBar(TRUE);
}
CTips::~CTips(void){};
uint16 CTips::GetStaticScrollCount()
{
IStatic *pIStatic;
pIStatic = (IStatic *)(((CStatic *)GetComponent(0))->m_pIControl);
if (!pIStatic)
return 0;
int pos;
int start, end, mid;
int height;
height = GetComponent(0)->m_rcLocation.dy;
start = 0;
mid = 100;
end = 200;
while (end - start > 1)
{
pos = ISTATIC_GoToLine(pIStatic, mid);
pos = ISTATIC_GoToLine(pIStatic, mid);
if (pos == mid)
{
start = mid;
mid = start + (end - start) / 2;
}
else
{
end = mid;
mid = start + (end - start) / 2;
}
}
ISTATIC_GoToLine(pIStatic, 0);
AEEApplet *pAEEApplet;
pAEEApplet = (AEEApplet *)GETAPPINSTANCE();
if (start + 1 > height / IDISPLAY_GetFontMetrics(pAEEApplet->m_pIDisplay, AEE_FONT_NORMAL, NULL, NULL))
return start + 1 - height / IDISPLAY_GetFontMetrics(pAEEApplet->m_pIDisplay, AEE_FONT_NORMAL, NULL, NULL);
else
return 0;
}
boolean CTips::HandleEvent(IApplet *pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
IStatic *pIStatic;
pIStatic = (IStatic *)(((CStatic *)GetComponent(0))->m_pIControl);
if (!pIStatic)
return FALSE;
if (m_wScrollCount < 0)
m_wScrollCount = GetStaticScrollCount();
AEERect rc;
int pos;
switch (eCode)
{
case EVT_KEY:
if (wParam == AVK_SELECT || wParam == AVK_CLR)
{
IMENUCTL_HandleEvent((IMenuCtl *)(((CMenuCtl *)GetComponent(CTLID_SYS_COMMAND_BAR))->m_pIControl), eCode, wParam, dwParam);
return FALSE;
}
switch (wParam)
{
case AVK_UP:
pos = ISTATIC_GoToLine(pIStatic, 0);
ISTATIC_GoToLine(pIStatic, pos - 1);
break;
case AVK_DOWN:
pos = ISTATIC_GoToLine(pIStatic, 101);
if (pos < m_wScrollCount)
ISTATIC_GoToLine(pIStatic, pos + 1);
else
ISTATIC_GoToLine(pIStatic, pos);
break;
default:
break;
}
return TRUE;
case EVT_COMMAND:
return FALSE;
default:
return TRUE;
}
return TRUE;
}
//初始化
void CTips::OnCreate()
{
this->AddSysCommand(0, (AECHAR *)L"返回");
AECHAR szAboutText[500];
AECHAR szCrLf[10];
STRTOWSTR("\n", szCrLf, sizeof(AECHAR) * 10);
MEMSET(szAboutText, 0, sizeof(AECHAR) * 500);
WSTRLCAT(szAboutText, (AECHAR*)L"工资、薪金所得的个人所得税按超额累进税率来计算:", 500);
WSTRLCAT(szAboutText, szCrLf, 500);
WSTRLCAT(szAboutText, (AECHAR*)L"1.计算出你的 月工资、薪金所得。", 500);
WSTRLCAT(szAboutText, szCrLf, 500);
WSTRLCAT(szAboutText, (AECHAR*)L"2.月应纳税所得额 = 月工资、薪金所得-800元(注:北京、上海为减去1000元,深圳为减去1600元.)", 500);
WSTRLCAT(szAboutText, szCrLf, 500);
WSTRLCAT(szAboutText, (AECHAR*)L"3.月应纳税额 = 月应纳税所得额×适用税率-速算扣除数", 500);
GetComponent(0)->SetText(szAboutText);
SetWindowLogo();
}
//获得命令
boolean CTips::OnCommand(uint16 wParam, uint32 dwParam)
{
AEEApplet *pAEEApplet = (AEEApplet *)GETAPPINSTANCE();
switch (wParam)
{
case 0:
this->NavigateToWindow(new CCalculateWindow(0));
return TRUE;
default:
break;
}
return CBrewWindow::OnCommand(wParam, dwParam);
}
//设置徽标
void CTips::SetWindowLogo()
{
BFCApp *app = (BFCApp *)GETAPPINSTANCE();
app->pApp->SetWindowLogo(WISDOMBFC_RES_FILE,RES_IMAGE2_WINDOWSLOGO);
}
boolean CTips::OnChildCommand(uint16 wID, uint16 wParam, uint32 dwParam){return TRUE;}