📄 sms.c
字号:
U32 tskbar; //底部任务栏
// 定义变量
MSG msg;
S16 quit = 0;
SMS *sms; //发送的短信
char phs[PHS_MAX_SIZE + 1]; //读进常用语
char notepad[TEXT_SIZE + 1]; //读进的记事本
char *notetemp;
// 初始化
struct MENU_ITEM menuitem[]= //菜单选项
{
1, 1, "导入",
1, 1, "保存",
0, 0, NULL,
};
dbgprintf( "### Enter 回复短信 ###" );
if((sms = (SMS *)Lmalloc(sizeof(SMS))) == NULL)
// if(MessageBox(0, "内存申请失败!", "警告", MB_ICONEXCLAMATION|MB_OK) == NULL)
return SEND_FAIL;
strcpy(sms->number, phone); //先把号码附给要发送短信
// 创建窗口和控件
mainwin = CreateWindow(WNDCLASS_WIN, "回复", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
send = CreateWindow(WNDCLASS_BUTTON, "\\发送短信", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 155)/2, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_fasongduanxin);
phrase = CreateWindow(WNDCLASS_BUTTON, "\\读入常用语", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 155)/2 + 105, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_changyongyu);
note = CreateWindow(WNDCLASS_MENU, (char *)zi_jishibenchazhao, WS_CHILD|MNS_ICON, (LCD_WIDTH - 155)/2 + 130, 23, BUTTON_W, BUTTON_W, mainwin, 0, menuitem);
smsedit = CreateWindow(WNDCLASS_EDITOR, "", WS_CHILD|ES_MULTI_REGULAR, (LCD_WIDTH - 156)/2, 46, 156, 83, mainwin, SMS_MAX + 1, NULL);
keyboard = CreateWindow(WNDCLASS_KEYBD, NULL, WS_CHILD|KBS_PINGYING|0xff, 1, 144, 157, 70, mainwin, 0, NULL);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
SetFocus(smsedit);
// 程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == send) //点击发送按钮
{
GetEditorStr(smsedit, sms->content, SMS_MAX);
if(strlen(sms->content) == 0)
MessageBox(mainwin, "短信内容不能为空", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
else
if(SendSMS(sms) == SEND_FAIL)
goto SENDFAIL;
}
else
if(msg.lparam == phrase) //点击常用语的记录
{
ChoosePhrase(phs);
GetEditorStr(smsedit, sms->content, SMS_MAX);
if(strlen(phs) >= (SMS_MAX - strlen(sms->content))) //判断短信内容加上常用语是否溢出
*(phs + (SMS_MAX - strlen(sms->content))) = '\0'; //截除多余的部分
strcat(sms->content, phs); //把phrase显示在编辑栏中的短信末尾;
SetWindowText(smsedit, sms->content, NULL);
}
else
if(msg.lparam == note) //点击记事本菜单
{
switch(msg.wparam)
{
case 0: //从记事本导入内容
notetemp = SearchNotepad(NAME_STYPE);
strcpy(notepad, notetemp);
GetEditorStr(smsedit, sms->content, SMS_MAX);
strncat(sms->content, notepad, (SMS_MAX - strlen(sms->content)));
SetWindowText(smsedit, sms->content, NULL);
break;
case 1: //将内容保存到记事本
if(GetEditorStr(smsedit, sms->content, SMS_MAX) == NULL)
MessageBox(mainwin, "不能保存空文件", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
else
{
if(SaveSmsNote(sms) == SAVE_SMS_FAIL)
MessageBox(mainwin, "保存失败", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
else
MessageBox(mainwin, "保存成功", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
}
break;
}
}
break;
case WM_ALARM:
GetEditorStr(smsedit, sms->content, SMS_MAX);
if(strlen(sms->content) != 0)
{
if(MessageBox(mainwin, "是否保存短信", "提醒", MB_ICONEXCLAMATION|MB_YESNO) == IDYES) //弹出提示框提醒
Add2SMSHistory(sms, SMS_SEND, NULL); // 保存当前短信到历史记录
}
quit = 1;
//发送消息收到短信
AdvSendMessage(GetCurTask()->id, (P_MESSAGE)(&msg), NO_SWAP_TASK);
break;
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow( mainwin );
Lfree(sms);
dbgprintf( "### Exit 回复短信 ###" );
return SEND_OK;
SENDFAIL:
Lfree(sms);
DestroyWindow( mainwin );
dbgprintf( "### Exit 回复短信 ###" );
return SEND_FAIL;
}
// 转发短信
//---------------------------------------------------------------
// TransmitSMS()
//
// transmit the SMS.
//
// Parameters:
// char *content - the content to be sended
//
// Returns:
// SEND_OK : success sending.
// SEND_FAIL : fail to send.
//---------------------------------------------------------------
STATUS TransmitSMS(char *content)
{
// 定义窗口和控件ID
U32 mainwin; //主窗口
U32 send; //发送按钮
U32 search; //查找按钮
U32 phone; //电话号码编辑栏
U32 smscontent; //短信内容显示框
// U32 scroll; //滚动条
U32 keyboard; //软键盘
U32 tskbar; //底部任务栏
// 定义变量
MSG msg;
SMS *sms; //发送的短信
S16 quit = 0;
S16 row = 1; //显示的第一个记录与记录列表首地址的偏移量
S16 length = SMS_DISP_MAX; //滚动条长度
S16 maxrow; //短信内容的总行数
char *notetemp;
// S16 flag;
dbgprintf( "### Enter 转发短信 ###" );
// 初始化
if((sms = (SMS *)Lmalloc(sizeof(SMS))) == NULL)
// if(MessageBox(0, "内存申请失败!", "警告", MB_ICONEXCLAMATION|MB_OK) == NULL)
return SEND_FAIL;
strcpy(sms->content, content);
maxrow = (U8)strlen(content)/LINE_MAX_SIZE+1; //短信的总行数
if(maxrow > length) //短信的总行数数超过最大显示行数时,设定滚动条长度为
{
length = maxrow;
}
// 创建窗口
mainwin = CreateWindow(WNDCLASS_WIN, "转发", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
send = CreateWindow(WNDCLASS_BUTTON, "\\发送短信", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 155)/2 + 137, 46, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_fasongduanxin);
search = CreateWindow(WNDCLASS_BUTTON, "查找", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 155)/2, 46, BUTTON_W, BUTTON_W, mainwin, 0, NULL);
phone = CreateWindow(WNDCLASS_EDITOR, "", WS_CHILD|ES_SINGLELINE|ES_RIGHT, (LCD_WIDTH - 155)/2 + 25, 46, 110, 20, mainwin, PHONE_MAX + 1, NULL);
smscontent = CreateWindow(WNDCLASS_EDITOR, content, WS_CHILD|ES_MULTI_REGULAR, (LCD_WIDTH - 155)/2, 68, 155, 75, mainwin, SMS_MAX + 1, NULL);
// scroll = CreateWindow(WNDCLASS_SCROLL, "", WS_CHILD|SBS_VERT, 137, 68, 20, 75, mainwin, MAKELONG(1, length - SMS_DISP_MAX + 1), NULL);
keyboard = CreateWindow(WNDCLASS_KEYBD, NULL, WS_CHILD|KBS_NUMBER|(KBS_NUMBER>>8), 1, 144, 157, 70, mainwin, 0, NULL);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
SetFocus(phone);
// 程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == send) //点击发送按钮
{
GetEditorStr(phone, sms->number, PHONE_MAX);
if(strlen(sms->number) == 0) //号码不为空时发送短信
MessageBox(mainwin, "请输入号码!", "提醒", MB_ICONEXCLAMATION|MB_OK);
else
if(SendSMS(sms) == SEND_FAIL)
goto SENDFAIL;
}
else
if(msg.lparam == search) //点击查找按钮
{
notetemp = SearchTelephoneBook();
strcpy(sms->number, notetemp);
SetWindowText(phone, sms->number, NULL);
}
break;
/* case WM_VSCROLL:
if(msg.lparam == scroll)
{
flag = 0;
switch (msg.wparam)
{
case SB_PAGEUP:
row -= SMS_DISP_MAX;
if (row < 1) row = 1;
break;
case SB_PAGEDOWN:
row += SMS_DISP_MAX;
if (row > length - SMS_DISP_MAX + 1) row = length - SMS_DISP_MAX + 1;
break;
case SB_LINEUP:
row -= 1;
if (row < 1) row = 1;
break;
case SB_LINEDOWN:
row += 1;
if (row > length - SMS_DISP_MAX + 1) row = length - SMS_DISP_MAX + 1;
break;
case SB_THUMBTRACK:
flag = 1;
break;
case SB_ENDSCROLL:
row = GetScrollPos(scroll, 0, 0, 0);
break;
};
if(!flag) //对滚动条的拖动操作
{
SetScrollPos(scroll, row, 0, 0);
SetWindowText(smscontent, (sms->content + (row - 1) * 11), NULL);
}
}
break;
*/
case WM_ALARM: //收到短信
quit = 1;
//发送消息收到短信
AdvSendMessage(GetCurTask()->id, (P_MESSAGE)(&msg), NO_SWAP_TASK);
break;
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
DestroyWindow( mainwin );
Lfree(sms);
dbgprintf( "### Exit 转发短信 ###" );
return SEND_OK;
SENDFAIL:
Lfree(sms);
DestroyWindow( mainwin );
dbgprintf( "### Exit 转发短信 ###" );
return SEND_FAIL;
}
//历史纪录保存
//---------------------------------------------------------------
// Add2SMSHistory()
//
// add the SMS to history.
//
// Parameters:
// SMS *newsms - the SMS which to be sending
// char *type - the type of the SMS
// char *time - the time of the SMS
// Returns:
// HIS_SAVE_SMS_OK : success adding history.
//---------------------------------------------------------------
STATUS Add2SMSHistory(SMS *newsms, char *type, char *unrtime)
{
// 定义变量
// WORD year, day, month, hour, minute, second; //时间参数
char name[NAME_MAX_SIZE + 1];
char *data;
S16 namelength;
S16 numlen;
S16 contentlen;
S16 datalen;
U16 timeoffset;
U16 nameoffset;
U16 numberoffset;
U16 flagoffset;
U16 contentoffset;
char timetemp[TIME_MAX_SIZE + 1];
char temp[TIME_MAX_SIZE + 1];
U8 linkflag = 0;
DBLACB *lacb;
LOCALSEARCHLIST *searchlist;
memset(name, 0x00, (NAME_MAX_SIZE + 1));
if(strlen(newsms->number) != 0) //当要保存的短信是自己写的时,且没有输入号码时,就不进行人名的查找,否则进行下面的人名查找操作
{
lacb = LinkDataBase(CARD_DATA_BASE);
linkflag = 1;
searchlist = LocalFindRecord(lacb, CARD_PHONE_FIELD, newsms->number, PRECISE_FULL_MATCH);
if(searchlist->num == 0)
{
strcpy(name, "\0");
}
else
{
nameoffset = *(searchlist->head[0].data); //姓名记录在data中的偏移量
if(!strlen(searchlist->head[0].data + nameoffset))
{
strcpy(name, "\0");
}
else
{
strcpy(name, (searchlist->head[0].data + nameoffset));
}
}
}
if(strlen(name) == 0) //当姓名项为空时,设姓名偏移量为空,姓名长度为空
{
nameoffset = 0;
namelength = 0;
}
else
{
nameoffset = 10 + TIME_MAX_SIZE + 1; //姓名的相对偏移
namelength = (S16)( strlen(name) );
}
if(strlen(newsms->number) == 0) //当号码为空时,设号码偏移量和长度为空
{
numlen = 0;
numberoffset = 0;
}
else
{
numlen = (S16)( strlen(newsms->number) );
numberoffset = 10 + TIME_MAX_SIZE + 1 + namelength + 1; //号码的相对偏移
}
contentlen = (S16)strlen(newsms->content);
datalen = (S16)(10 + numlen + 1 + contentlen + 1 + TIME_MAX_SIZE + 1 + strlen(name) + 1 + TYPE_MAX_SIZE + 1);
if((data = (char *)Lmalloc(datalen)) == NULL)
// if(MessageBox(0, "内存申请失败!", "警告", MB_ICONEXCLAMATION|MB_OK) == NULL)
return SAVE_SMS_FAIL;
if(strcmp(type, SMS_UNREAD))
{
ASIX_DATE date;
ASIX_TIME time;
ReadDateTime( &date, &time ); //获取系统时间
sprintf(temp, "%u", date.year);
strcpy(timetemp, temp);
if(date.month < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.month);
strcat(timetemp, temp);
if(date.day < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", date.day);
strcat(timetemp, temp);
if(time.hour < 10)
{
strcat(timetemp, "0");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -