📄 sms.c
字号:
}
sprintf(temp, "%u", time.hour);
strcat(timetemp, temp);
if(time.minute < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.minute);
strcat(timetemp, temp);
if(time.second < 10)
{
strcat(timetemp, "0");
}
sprintf(temp, "%u", time.second);
strcat(timetemp, temp);
}
else
{
strcpy(timetemp, unrtime);
}
timeoffset = 10; //时间的相对偏移
Word2Bytes(data, timeoffset);
Word2Bytes((data + 2), nameoffset);
// if(strlen(newsms->number) == 0)
// {
// numlen = 0;
// numberoffset = 0;
// }
// else
// {
// numlen = (S16)(strlen(newsms->number) + 1);
// numberoffset = 10 + TIME_MAX_SIZE + 1 + namelength; //号码的相对偏移
// }
Word2Bytes((data + 4), numberoffset);
flagoffset = 10 + TIME_MAX_SIZE + 1 + namelength + 1 + numlen + 1; //类型值的相对偏移
Word2Bytes((data + 6), flagoffset);
contentoffset = 10 + TIME_MAX_SIZE + 1 + namelength + 1 + numlen + 1 + TYPE_MAX_SIZE + 1; //短信内容的相对偏移
Word2Bytes((data + 8), contentoffset);
//向里面添值
strcpy((data + timeoffset), timetemp);
if(nameoffset != 0)
{
strcpy((data + nameoffset), name);
}
if(numberoffset != 0)
{
strcpy((data + numberoffset), newsms->number);
}
strcpy((data + flagoffset), type);
strcpy((data + contentoffset), newsms->content);
if(linkflag == 1)
DetachDataBase( lacb );
lacb = LinkDataBase(SMSH_DATA_BASE);
LocalAddRecord(lacb, data, datalen);
DetachDataBase( lacb );
Lfree(data);
return SAVE_SMS_OK;
}
// 读入历史记录
//---------------------------------------------------------------
// LoadHistory()
//
// read the history list.
//
// Parameters:
// SMSHISTORY **list - the pointer of the history list
// char *type - the type of the SMS which to be read
// S16 *num - the number of history
//
// Returns:
// HIS_SAVE_SMS_OK : success adding history.
//---------------------------------------------------------------
void LoadHistory(char *type, S16 *num, SMSHISTORY **list) //(这里的历史记录暂时自己写,应该是通过数据库读取)
{
DBLACB *lacb;
LOCALSEARCHLIST *searchlist;
// CreateDataBase();
lacb = LinkDataBase(SMSH_DATA_BASE);
if(strcmp(type, SMS_ALL))
searchlist = LocalFindRecord(lacb, SMSH_TYPE_FIELD, type, PRECISE_FULL_MATCH);
else
searchlist = LocalFindRecord(lacb, SMSH_TIME_FIELD, NULL, GLOBAL_SEARCH);
*num = searchlist->num;
GetSMSList(list, *num, searchlist);
// DelOldSearchList( searchlist );
DetachDataBase( lacb );
return;
}
SEARCH *SupSearch(S16 *num, SMSHISTORY **list)
{
//定义窗口和控件ID
U32 mainwin; //主窗口
U32 type; //搜索类型选择 选择框
U32 keyword; //关键字输入栏 编辑栏
U32 tip; //静态框
U32 ok; //确定 按钮
U32 cancel; //取消 按钮
U32 keyboard; //软键盘
U32 tskbar; //底部任务栏
//定义函数变量
MSG msg;
S16 quit = 0, i = 0;
char searchtype = -1; //搜索类型
char temp[NAME_MAX_SIZE + 1]; //关键字
LOCALSEARCHLIST *searchlist = NULL; //查找的结果列表
DBLACB *lacb;
SEARCH *search;
//初始化
SL_ITEM item[] =
{
SL_UNCHECKED, "部分匹配",
SL_UNCHECKED, "完全匹配",
0, NULL,
};
dbgprintf( "### Enter 查找短信 ###" );
if((search = (SEARCH *)Lmalloc(sizeof(SEARCH))) == NULL)
return NULL;
// strcpy(newpath, currentdir);
//创建窗口控件
mainwin = CreateWindow(WNDCLASS_WIN, "查找", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
type = CreateWindow(WNDCLASS_SELECT, "类型选择", WS_CHILD|SLS_ENABLE|SLS_FRAME|SLS_RADIOBOX, (LCD_WIDTH - 100)/2, 23, 100, 50, mainwin, 0, item);
tip = CreateWindow(WNDCLASS_STATIC, "请输入姓名:", WS_CHILD|SS_TEXT, (LCD_WIDTH - 150)/2, 73, 150, 17, mainwin, 0, NULL);
keyword = CreateWindow(WNDCLASS_EDITOR, "", WS_CHILD|ES_SINGLE_REGULAR, (LCD_WIDTH - 150)/2, 90, 150, 20, mainwin, 12, NULL);
ok = CreateWindow(WNDCLASS_BUTTON, "确定", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2, 111, 40, 20, mainwin, 0, NULL);
cancel = CreateWindow(WNDCLASS_BUTTON, "取消", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 120)/2 + 80, 111, 40, 20, mainwin, 0, NULL);
keyboard = CreateWindow(WNDCLASS_KEYBD, "", WS_CHILD|KBS_HANDWRITE|0xff, 1, 148, 157, 70, mainwin, 0, NULL);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
SetFocus(keyword);
lacb = LinkDataBase(SMSH_DATA_BASE);
//程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == ok) //点击确定
{
switch(searchtype)
{
case PRECISE_PART_MATCH:
GetEditorStr(keyword, temp, (NAME_MAX_SIZE - 1)); //读出关键字
if(strlen(temp) == 0) //关键字为0时
{
MessageBox(mainwin, "请输入要查找的姓名!", "", MB_ICONEXCLAMATION|MB_OK);
}
else
{
searchlist = LocalFindRecord(lacb, SMSH_NAME_FIELD, temp, searchtype);
quit = 1;
}
break;
case PRECISE_FULL_MATCH:
GetEditorStr(keyword, temp, (NAME_MAX_SIZE - 1)); //读出关键字
if(strlen(temp) == 0) //关键字为0时
{
MessageBox(mainwin, "请输入要查找的姓名!", "", MB_ICONEXCLAMATION|MB_OK);
}
else
{
searchlist = LocalFindRecord(lacb, SMSH_NAME_FIELD, temp, searchtype);
quit = 1;
}
break;
case -1:
MessageBox(mainwin, "请选择查找类型!", "提醒", MB_ICONEXCLAMATION|MB_OK);
break;
}
}
else
if(msg.lparam == cancel) //点击取消按钮
{
quit = 1;
searchtype = -1;
}
break;
case WM_SELECTBOX:
if(msg.lparam == type) //点选选择框
{
if(item[0].state == SL_CHECKED)
{
if(searchtype != PRECISE_PART_MATCH)
searchtype = PRECISE_PART_MATCH;
}
else
if(item[1].state == SL_CHECKED)
{
if(searchtype != PRECISE_FULL_MATCH)
searchtype = PRECISE_FULL_MATCH;
}
else
searchtype = -1;
}
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);
}
//解析数据
if(searchtype == -1)
{
search->searchtype = searchtype;
}
else
{
if( searchlist != NULL )
{
strcpy(search->keyword, temp);
search->searchtype = searchtype;
*num = searchlist->num;
for(i = 0; i < searchlist->num; i++)
{
Lfree(list[i]);
}
// if(i != searchlist->num)
// Lfree(list);
GetSMSList(list, *num, searchlist);
}
}
DestroyWindow( mainwin );
DetachDataBase( lacb );
dbgprintf( "### Exit 查找短信 ###" );
return search;
}
void GetSMSList(SMSHISTORY **nowlist, S16 listnum, LOCALSEARCHLIST *searchlist)
{
S16 i;
U16 timeoffset;
U16 nameoffset;
U16 numberoffset;
U16 flagoffset;
U16 contentoffset;
char *newdata;
if(searchlist->head == 0)
{
*nowlist = NULL;
return;
}
for(i = 0; i < listnum; i++)
{
if((nowlist[i] = (SMSHISTORY *)Lmalloc(sizeof(SMSHISTORY))) == NULL)
{
// MessageBox(0, "读入历史纪录错误!", "提醒", MB_ICONEXCLAMATION|MB_OK);
return;
}
}
for(i = 0; i < listnum; i++)
{
newdata = (char *)(searchlist->head[i].data + 12); //指针跳过头信息
ByteReversal(&timeoffset, newdata); //时间记录在data中的偏移量
ByteReversal(&nameoffset, newdata + 2); //姓名记录在data中的偏移量
ByteReversal(&numberoffset, newdata + 4); //号码记录在data中的偏移量
ByteReversal(&flagoffset, newdata + 6); //类型记录在data中的偏移量
ByteReversal(&contentoffset, newdata+ 8); //内容记录在data中的偏移量
(nowlist[i])->index = searchlist->head[i].index;
strcpy((nowlist[i])->flag, (newdata + flagoffset));
if(nameoffset != 0)
strcpy((nowlist[i])->name, (newdata + nameoffset)); //首地址偏移两个字节是发信人姓名
else
strcpy((nowlist[i])->name, "\0");
if(numberoffset != 0)
strcpy((nowlist[i])->sms.number, (newdata + numberoffset)); //首地址偏移4个字节是电话号码
else
strcpy((nowlist[i])->sms.number, "\0");
strcpy((nowlist[i])->sms.content, (newdata + contentoffset)); //首地址偏移8个字节是短信内容
strcpy((nowlist[i])->time, (newdata + timeoffset)); //首地址指向的第一项是时间
}
DelOldSearchList(searchlist);
return;
}
// 外部函数
STATUS AddPhonetoBook(char *number)
{
char name[MAXNAMELEN] = "";
// 保存号码到电话本
if( SaveCallIntoPhbook( number, name ) == SAVE_CANCEL )
return SAVE_SMS_FAIL;
return SAVE_SMS_OK;
}
/*
STATUS SaveSmsNote(SMS *sms)
{
return SAVE_SMS_OK;
}
*/
char *SearchTelephoneBook()
{
char *num;
// 查找电话号码
num = GetCallFromPhbook();
return num;
}
/*
char *SearchNotepad(S16 type, char *path)
{
char *note = "Hello, World!";
return note;
}
*/
void ModifySMS(SMSHISTORY *nowitem) //把未读短信改为已读短信
{
char *data;
char *newdata;
DBLACB *lacb;
S16 namelen;
S16 numlen;
S16 datalen;
lacb = LinkDataBase(SMSH_DATA_BASE);
data = LocalReadRecord(lacb, nowitem->index);
if(strlen(nowitem->name) == 0)
namelen = 0;
else
namelen = (S16)(strlen(nowitem->name) + 1);
if(strlen(nowitem->sms.number) == 0)
numlen = 0;
else
numlen = (S16)(strlen(nowitem->sms.number) + 1);
newdata = data + 12 + 10 + strlen(nowitem->time) + 1 + namelen + numlen;
strcpy(newdata, SMS_READ);
newdata = data + 12;
datalen = (S16)(10 + strlen(nowitem->time) + 1 + namelen + numlen + 2 + strlen(nowitem->sms.content) + 1);
LocalModifyRecord(lacb, nowitem->index, newdata, datalen);
strcpy(nowitem->flag, SMS_READ);
Lfree(data);
DetachDataBase(lacb);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -