📄 smsh.c
字号:
else
{
SetWindowText(man, nowhis->name, NULL);
}
strncpy(disptime, (nowhis->time + 2), 2);
*(disptime + 2) = '\0';
strcat(disptime, " ");
strncat(disptime, (nowhis->time + 4), 2);
strcat(disptime, ".");
strncat(disptime, (nowhis->time + 6), 2);
}
}
}
}
}
}
break;
case WM_VSCROLL:
if ( msg.lparam == vscroll )
{
if(listnum <= HIS_DISP_MAX) //当常用语个数小于最大显示个数时,不做响应
{
break;
}
switch (msg.wparam)
{
case SB_PAGEUP:
row -= HIS_DISP_MAX;
if (row < 1) row = 1;
break;
case SB_PAGEDOWN:
row += HIS_DISP_MAX;
if (row > (length - HIS_DISP_MAX + 1)) row = length - HIS_DISP_MAX + 1;
break;
case SB_LINEUP:
row -= 1;
if (row < 1) row = 1;
break;
case SB_LINEDOWN:
row += 1;
if (row > (length - HIS_DISP_MAX + 1)) row = length - HIS_DISP_MAX + 1;
break;
case SB_THUMBTRACK:
flag = 1;
break;
case SB_ENDSCROLL:
row = GetScrollPos(vscroll,0,0,0);
flag = 0;
break;
}
if(!flag) //对拖动操作的处理
{
SetScrollPos(vscroll,row,0,0); // 滚动条操作定位
if(orderflag == UP) //当前顺序为升序
{
for(i=0; i<HIS_DISP_MAX; i++) //更新列表显示
{
if((i + row - 1) < listnum) //数组没结束时显示,否则后面列表为空
{
if(strlen((*(nowlist + i + row - 1))->name) == 0)
{
if(strlen((*(nowlist + i + row - 1))->sms.number) != 0)
SetWindowText(history[i], (*(nowlist + i + row -1))->sms.number, NULL);
else
SetWindowText(history[i], "未写完短信", NULL);
}
else
SetWindowText(history[i], (*(nowlist + i + row - 1))->name, NULL);
switch(*((*(nowlist + i + row - 1))->flag))
{
case '1': //未读短信
SetWindowText(property[i], NULL, (char *)zi_weidu);
break;
case '2': //已读短信
SetWindowText(property[i], NULL, (char *)zi_yidu);
break;
case '3': //发送短信
SetWindowText(property[i], NULL, (char *)zi_yifasong);
break;
}
}
else
{
SetWindowText(history[i], "", NULL);
SetWindowText(property[i], NULL, NULL);
}
}
}
else //当前顺序为降序
{
for(i=0; i<HIS_DISP_MAX; i++) //更新列表显示
{
if((i + row - 1) < listnum) //数组没结束时显示,否则后面列表为空
{
if(strlen((*(nowlist2 + i + row -1))->name) == 0)
{
if(strlen((*(nowlist2 + i + row - 1))->sms.number) != 0)
SetWindowText(history[i], (*(nowlist2 + i + row -1))->sms.number, NULL);
else
SetWindowText(history[i], "未写完短信", NULL);
}
else
SetWindowText(history[i], (*(nowlist2 + i + row -1))->name, NULL);
switch(*((*(nowlist2 + i + row - 1))->flag))
{
case '1': //未读短信
SetWindowText(property[i], NULL, (char *)zi_weidu);
break;
case '2': //已读短信
SetWindowText(property[i], NULL, (char *)zi_yidu);
break;
case '3': //发送短信
SetWindowText(property[i], NULL, (char *)zi_yifasong);
break;
}
}
else
{
SetWindowText(history[i], "", NULL);
SetWindowText(property[i], NULL, NULL);
}
}
}
}
}
break;
case WM_ALARM:
/* if(msg.lparam == smh)
{
for(i=0; i<listnum; i++) //释放结构列表的空间
{
Lfree(list[i]);
}
LoadHistory(SMS_UNREAD, &listnum, nowlist);
// strcpy(nowflag, SMS_UNREAD);
length = HIS_DISP_MAX;
if(listnum >= HIS_DISP_MAX) //判断新列表是否需要滚动条
{
length = listnum;
}
for(i=0; i<listnum; i++) //创建新的逆向列表
{
nowlist2[i] = nowlist[listnum - i - 1];
}
if(orderflag == UP) //当前排序为升序时
{
for(i=0; i<HIS_DISP_MAX; i++) //更新列表显示
{
if(i < listnum) //数组没结束时显示,否则后面列表为空
SetWindowText(history[i], (*(nowlist + i))->name, NULL);
else
SetWindowText(history[i], "", NULL);
}
}
else //当前列表为降序时
{
for(i=0; i<HIS_DISP_MAX; i++) //更新列表显示
{
if(i < listnum) //数组没结束时,显示,否则后面列表为空
SetWindowText(history[i], (*(nowlist2 + i))->name, NULL);
else
SetWindowText(history[i], "", NULL);
}
}
SetScrollRange(vscroll, 1, (U16)(length - HIS_DISP_MAX + 1)); //重新设置滚动条长度,并定位到最顶端
SetScrollPos(vscroll, 1, 0, 0);
row = 1; //偏移量也置为1
break;
}
else
*/ if(msg.lparam == ALARM_SMS)
{
for(i=0; i<listnum; i++) //释放结构列表的空间
{
Lfree(nowlist[i]);
}
LoadHistory(SMS_UNREAD, &listnum, nowlist);
listnum = ReadSMSHistory(0, listnum, nowlist);
}
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
}
if(searchnow != NULL)
Lfree(searchnow);
if(searchprev != NULL)
Lfree(searchprev);
for(i=0; i<listnum; i++)
{
Lfree(nowlist[i]);
Lfree(nowlist2[i]);
}
DestroyWindow( mainwin );
DetachDataBase( lacb );
dbgprintf( "### Exit 浏览短信 ###" );
return;
}
//阅读短信
//---------------------------------------------------------------
// ReadSMSHistory()
//
// Browse the history of SMS.
//
// Parameters:
// S16 no - the offset of the SMS to the first SMS.
// S16 listnum - the number of the SMS list.
// SMSHISTORY **nowlist - It's the list that is displayed now.
//
// Returns:
// S16 listnum - the number of the SMS list.
//---------------------------------------------------------------
int ReadSMSHistory(S16 no, S16 listnum, SMSHISTORY **nowlist) //no是选定浏览的记录在列表中的序号(-1表示没有选),nowlist是当前列表
{
// 定义窗口和控件ID
U32 mainwin; //主窗口
U32 reply; //回复按钮
U32 transmit; //转发按钮
U32 del; //删除按钮
U32 save; //保存菜单
U32 first,prev,next,last; //第一条,前一条,下一条,最后一条
U32 man; //人名显示框
U32 time; //时间显示框
U32 content; //短信内容框
U32 tskbar; //底部任务栏
// 定义变量
MSG msg;
S16 quit = 0;
DBLACB *lacb;
S16 temp;
char disptime[TIME_DISP_MAX + 1];
// 初始化
struct MENU_ITEM menuitem[]= //保存的菜单选项
{
1, 1, "电话本",
1, 1, "记事本",
0, 0, NULL,
};
if(no == -1) //假如没有读取(-1表示没有读取),则默认第一条为当前记录
{
no = 0;
}
dbgprintf( "### Enter 阅读短信 ###" );
// 创建窗口和控件
mainwin = CreateWindow(WNDCLASS_WIN, "阅读短信", WS_OVERLAPPEDWINDOW, 0, 0, PHY_LCD_W, PHY_LCD_H, 0, 0, NULL);
reply = CreateWindow(WNDCLASS_BUTTON, "\\回复短信", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 130)/2, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_huifu);
transmit = CreateWindow(WNDCLASS_BUTTON, "\\转发短信", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 130)/2 + 25, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_zhuanfa);
del = CreateWindow(WNDCLASS_BUTTON, "\\删除", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 130)/2 + 50, 23, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_cancel);
save = CreateWindow(WNDCLASS_MENU, (char *)zi_save, WS_CHILD|MNS_ICON, (LCD_WIDTH - 155)/2 + 110, 23, BUTTON_W, BUTTON_W, mainwin, 0, menuitem);
if(strlen((*(nowlist + no))->name) == 0)
man = CreateWindow(WNDCLASS_STATIC, (*(nowlist + no))->sms.number, WS_CHILD|SS_TEXT|SS_BOARD, (LCD_WIDTH - 155)/2, 45, 75, BUTTON_W, mainwin, 0, NULL);
else
man = CreateWindow(WNDCLASS_STATIC, (*(nowlist + no))->name, WS_CHILD|SS_TEXT|SS_BOARD, (LCD_WIDTH - 155)/2, 45, 75, BUTTON_W, mainwin, 0, NULL);
strncpy(disptime, ((*(nowlist + no))->time + 2), 2);
*(disptime + 2) = '\0';
strcat(disptime, " ");
strncat(disptime, ((*(nowlist + no))->time + 4), 2);
strcat(disptime, ".");
strncat(disptime, ((*(nowlist + no))->time + 6), 2);
time = CreateWindow(WNDCLASS_STATIC, disptime, WS_CHILD|SS_TEXT|SS_BOARD, (LCD_WIDTH - 155)/2 + 80, 45, 70, BUTTON_W, mainwin, 0, NULL);
content = CreateWindow(WNDCLASS_EDITOR, (*(nowlist + no))->sms.content, WS_CHILD|ES_MULTI_REGULAR, (LCD_WIDTH - 156)/2, 68, 156, 120, mainwin, SMS_MAX, NULL);
first = CreateWindow(WNDCLASS_BUTTON, "\\第一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 95)/2, 197, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_first);
prev = CreateWindow(WNDCLASS_BUTTON, "\\前一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 75)/2 + 25, 197, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_prev);
next = CreateWindow(WNDCLASS_BUTTON, "\\后一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 75)/2 + 50, 197, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_next);
last = CreateWindow(WNDCLASS_BUTTON, "\\最后一个", WS_CHILD|BS_REGULAR, (LCD_WIDTH - 75)/2 + 75, 197, BUTTON_W, BUTTON_W, mainwin, 0x00140014, (char *)zi_last);
tskbar = CreateWindow(WNDCLASS_TSKBAR, NULL, WS_CHILD|TBS_TYPICAL, 0, 0, 0, 0,mainwin, 0, NULL);
//连接数据库
// CreateDataBase( ); //创建数据库文件
lacb = LinkDataBase( SMSH_DATA_BASE ); //链接短信历史纪录数据库
if(no == 0) //当前记录为第一个时,灰化第一条和前一条按钮
{
EnableWindow(first, FALSE);
EnableWindow(prev, FALSE);
}
if(no == (listnum - 1)) //当前记录最后一个时,灰化后一个和最后一个按钮
{
EnableWindow(last, FALSE);
EnableWindow(next, FALSE);
}
// Add2SMSHistory(&((*(nowlist + no))->sms), SMS_READ, NULL);
// LocalDelRecord( lacb, (*(nowlist + no))->index ); //从数据库中删除
if(!strcmp((*(nowlist + no))->flag, SMS_UNREAD)) //如果是未读记录,改为已读
ModifySMS((*(nowlist + no))); //把未读短信改为已读短信
// 程序开始
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
case WM_COMMAND:
if(msg.lparam == reply) //点击回复按钮
{
if(no == -1) //当没有短信时,弹出消息框提示
MessageBox(mainwin, "没有可回复的短信!!!", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
else
ReplySMS((*(nowlist + no))->sms.number); //调用回复函数,并把当前记录的号码给回复函数
}
else
if(msg.lparam == transmit) //点击转发按钮
{
if(no == -1) //当没有短信时,弹出消息框提示
MessageBox(mainwin, "没有可发送的短信!!!", "提醒", MB_ICONEXCLAMATION|MB_OK); //弹出提示框提醒
else
TransmitSMS((*(nowlist + no))->sms.content); //调用转发函数,并把当前记录的内容给转发函数
}
else
if(msg.lparam == del) //点击删除按钮
{
if(no == -1) //判断当前列表是否为空
{
if(MessageBox(mainwin, "当前列表已经为空!没有可删除的记录!", "提醒", MB_ICONEXCLAMATION|MB_OK) == IDOK)
quit = 1;
}
else
if(no == (listnum - 1)) //是最后一个
{
EnableWindow(last, FALSE);
EnableWindow(next, FALSE);
if(no == 0) //判断是否为第一个,是则弹出消息框提示历史纪录已经为空
{
EnableWindow(first, FALSE);
EnableWindow(prev, FALSE);
//删除操作处理
LocalDelRecord( lacb, (*(nowlist + no))->index ); //从数据库中删除
Lfree(*(nowlist + no)); //从当前列表中删除
for(temp=no; temp<(listnum - 1); temp++)
{
*(nowlist + temp) = *(nowlist + temp + 1);
}
*(nowlist + temp) = NULL;
listnum = 0; //列表个数为空
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -