将GD32系列MCU荣获“最佳本土芯片”奖 这篇文章的内容做成TXT文件,开始用GD32来阅读..
利用UCGUI来创建一个multiedit和两个button控件
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { FRAMEWIN_CreateIndirect, "文本阅读", 0, 0, 0, 240,320,FRAMEWIN_CF_MOVEABLE,0}, { MULTIEDIT_CreateIndirect, "MULTIEDIT", GUI_ID_MULTIEDIT0, 18, 16, 195,239,0,0}, { BUTTON_CreateIndirect, "上一页", GUI_ID_BUTTON0, 18, 261,57, 26, 0,0}, { BUTTON_CreateIndirect, "下一页", GUI_ID_BUTTON1, 154,261,57, 26, 0,0} };
UCOS的任务分配,触屏检测,画面重绘,文本阅读功能函数。下面是回调函数:
static void _cbCallback(WM_MESSAGE * pMsg) { int NCode, Id; WM_HWIN hWin = pMsg->hWin; hWinEbook = hWin; switch (pMsg->MsgId) { case WM_PAINT: PaintDialog(pMsg); break; case WM_INIT_DIALOG: InitDialog(pMsg); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case GUI_ID_BUTTON1: if(NCode==WM_NOTIFICATION_RELEASED) { gDirFlag = 0; if(TXT_Info.TXT_Count < TXT_Info.TXT_MaxCount ) { TXT_Info.TXT_Count++; TXT_Info.TXT_AddrCount += TXT_Info.TXT_ReadNumber[2]; UpdataEbook = 1; } } break; case GUI_ID_BUTTON0: if(NCode==WM_NOTIFICATION_RELEASED) { if(gDirFlag == 0) gDirFlag = 1; if(TXT_Info.TXT_Count != 0) { TXT_Info.TXT_Count--; UpdataEbook = 1; if(gDirFlag == 1) { TXT_Info.TXT_AddrCount -= (TXT_BUF_MAX); gDirFlag = 2; } else if(FlagTable[TXT_Info.TXT_Count] != TXT_BUF_MAX && FlagTable[TXT_Info.TXT_Count + 1] != TXT_BUF_MAX) { TXT_Info.TXT_AddrCount -= (TXT_BUF_MAX - 1); } else if(FlagTable[TXT_Info.TXT_Count] == TXT_BUF_MAX && FlagTable[TXT_Info.TXT_Count + 1] != TXT_BUF_MAX) { TXT_Info.TXT_AddrCount -= (TXT_BUF_MAX - 1); } else if(FlagTable[TXT_Info.TXT_Count] != TXT_BUF_MAX && FlagTable[TXT_Info.TXT_Count + 1] == TXT_BUF_MAX) { TXT_Info.TXT_AddrCount -= TXT_BUF_MAX; } else { TXT_Info.TXT_AddrCount -= TXT_BUF_MAX; } } } break; } break; default: WM_DefaultProc(pMsg); } }
在这个部分需要处理好的是,每次截取部分TXT文件的数据后需要判断是否会乱码,一个汉字是两个字节,如果再截取200个字节的最后一个自己是一个汉字的数据,那么这样如果直接将显示数据设置给空间,那么只会的数据基本上都会乱码。在MULTIEDIT控件中需要自己插入换行 \n。
下面是整体的效果图: