本帖最后由 zhanghuichun 于 2014-11-15 19:39 编辑
/*
短信的界面
*/
void GUI_Message(void)
{
WM_HWIN hButton1;
WM_HWIN hButton2;
WM_HWIN hButton3;
WM_HWIN hButton4;
WM_HWIN hText1;
WM_HWIN hText2;
WM_HWIN hText3;
WinPara.hMessage = WM_CreateWindowAsChild(0, 0,
WinPara.xSizeWin, WinPara.ySizeWin,
WinPara.hWinMain,
WM_CF_SHOW | WM_CF_STAYONTOP,
_cbMessage, 0);
hButton1 = BUTTON_CreateEx(20, 5,
90, 30,
WinPara.hMessage,
WM_CF_SHOW, 0, GUI_ID_BUTTON1);
BUTTON_SetText(hButton1,"New Message");
BUTTON_SetSkin(hButton1, BUTTON_SKIN_FLEX);
hButton2 = BUTTON_CreateEx(130, 5,
90, 30,
WinPara.hMessage,
WM_CF_SHOW, 0, GUI_ID_BUTTON2);
BUTTON_SetText(hButton2,"EXIT");
BUTTON_SetSkin(hButton2, BUTTON_SKIN_FLEX);
hButton3 = BUTTON_CreateEx(20, 265,
90, 30,
WinPara.hMessage,
WM_CF_SHOW, 0, GUI_ID_BUTTON3);
BUTTON_SetText(hButton3,"Last");
BUTTON_SetSkin(hButton3, BUTTON_SKIN_FLEX);
hButton4 = BUTTON_CreateEx(130, 265,
90, 30,
WinPara.hMessage,
WM_CF_SHOW, 0, GUI_ID_BUTTON4);
BUTTON_SetText(hButton4,"Next");
BUTTON_SetSkin(hButton4, BUTTON_SKIN_FLEX);
hText1 = TEXT_CreateEx(10, 45,
WinPara.xSizeWin-20, 40,
WinPara.hMessage,
WM_CF_SHOW,
TEXT_CF_LEFT|TEXT_CF_VCENTER,
GUI_ID_TEXT1,
"Time:");
TEXT_SetTextColor(hText1, GUI_WHITE);
hText2 = TEXT_CreateEx(10, 85,
WinPara.xSizeWin-20, 40,
WinPara.hMessage,
WM_CF_SHOW,
TEXT_CF_LEFT|TEXT_CF_VCENTER,
GUI_ID_TEXT2,
"Number:");
TEXT_SetTextColor(hText2, GUI_WHITE);
hText3 = TEXT_CreateEx(10, 125,
WinPara.xSizeWin-20, 70,
WinPara.hMessage,
WM_CF_SHOW,
TEXT_CF_LEFT|TEXT_CF_TOP,
GUI_ID_TEXT3,
"Text:");
TEXT_SetTextColor(hText3, GUI_WHITE);
}
/*
短信界面的回调函数
*/
static void _cbMessage(WM_MESSAGE * pMsg)
{
WM_HWIN hWin;
WM_HWIN hButton;
WM_HWIN hText;
int xSize,ySize;
int Id,NCode;
hWin = pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
if(NCode == WM_NOTIFICATION_RELEASED )
{
if(Id == GUI_ID_BUTTON1)
{
GUI_NewMessage();
}
else if(Id == GUI_ID_BUTTON2)
{
//lseek_num = 0;
messagesnum = 0;
WM_DeleteWindow(WinPara.hMessage);
}
else if(Id == GUI_ID_BUTTON3)
{
if(messagesnum > 0)
{
int addr = lseek_num[messagesnum - 1];
char databuff[200];
char utf8buff[200];
messagesnum--;
myres = f_open(&myfsrc, "0:/messages.txt", FA_READ | FA_OPEN_EXISTING);
f_lseek(&myfsrc, addr);
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT1);
TEXT_SetText(hText, databuff);
addr += strlen(databuff) + 1;
f_lseek(&myfsrc, addr);
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT2);
TEXT_SetText(hText, databuff);
addr += strlen(databuff) + 1;
f_lseek(&myfsrc, addr);
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT3);
StrUnicodeToUTF8(databuff, utf8buff);
TEXT_SetText(hText, utf8buff);
f_close(&myfsrc);
}
else
{
GUI_MessageBox("No messages"," ",GUI_MESSAGEBOX_CF_MOVEABLE);
}
}
else if(Id == GUI_ID_BUTTON4)
{
char databuff[200];
char utf8buff[200];
myres = f_open(&myfsrc, "0:/messages.txt", FA_READ | FA_OPEN_EXISTING);
lseek_num[0] = 0;
f_lseek(&myfsrc, lseek_num[messagesnum]);
if(!f_eof(&myfsrc))
{
int addr;
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT1);
TEXT_SetText(hText, databuff);
//lseek_num[messagesnum] += strlen(databuff) + 1;
addr = lseek_num[messagesnum] + strlen(databuff) + 1;
f_lseek(&myfsrc, addr);
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT2);
TEXT_SetText(hText, databuff);
addr += strlen(databuff) + 1;
f_lseek(&myfsrc, addr);
f_gets(databuff, sizeof(databuff), &myfsrc);
//USART_printf(USART1, "\r\n $%s$ \r\n", databuff);
hText = WM_GetDialogItem(pMsg->hWin, GUI_ID_TEXT3);
StrUnicodeToUTF8(databuff, utf8buff);
TEXT_SetText(hText, utf8buff);
//lseek_num[messagesnum] += strlen(databuff) + 1;
lseek_num[messagesnum+1] = addr + strlen(databuff) + 1;
messagesnum++;
}
else
{
GUI_MessageBox("No messages"," ",GUI_MESSAGEBOX_CF_MOVEABLE);
}
f_close(&myfsrc);
}
}
break;
case WM_PAINT:
//
// Draw background
//
xSize = WM_GetWindowSizeX(hWin);
ySize = WM_GetWindowSizeY(hWin);
GUI_SetColor(GUI_DARKGRAY);
GUI_FillRect(0,0,xSize,ySize);
break;
}
}
短信读取界面:
发送短信界面: