我建了5个EDIT小工具,定义一个数组来存储数据,最大输入字符数为4, 然后想获取框中输入的数值直接显示在背景上,但是一直显示乱码,而且输出的不止4个字符,纠结了一天,感觉快崩溃了,以下贴上部分代码:static void _bgcallback(WM_MESSAGE *pMsg)
{
WM_HWIN hwin;
EDIT_Handle edit;
static U8 text;
int i, ID;
char buffer[4];
switch (pMsg ->MsgId)
{
case WM_PAINT:
GUI_DrawBitmapEx(&bmjoba, 0, 0, 0, 0, 2500, 1875);
GUI_SetTextMode(GUI_TEXTMODE_TRANS);
GUI_SetFont(&GUI_Font8x16);
GUI_SetColor(GUI_BLACK);
GUI_DispStringAt(name, 130, 40);
GUI_DispStringAt("MEDICINE", 5, 40);
GUI_DispStringAt("LIFESPAN", 5, 80);
GUI_DispStringAt("POSITION", 5, 120);
GUI_DispStringAt("DOSE", 5, 160);
GUI_SetFont(&GUI_Font13B_1);
GUI_DispStringAt("(ALTERNATIVE)", 40, 160);
GUI_SetFont(&GUI_Font8x16x2x2);
GUI_SetColor(GUI_MAGENTA);
GUI_SetTextAlign(GUI_TA_VCENTER | GUI_TA_HCENTER);
GUI_DispStringAt("RECORDING", 160, 10);
if (text)
{
for (i = 0; i < 4; i++)
{
edit = WM_GetDialogItem(dialogwin, GUI_ID_EDIT1 + i);
GUI_SetFont(&GUI_Font8x16);
GUI_SetColor(GUI_BLACK);
EDIT_GetText(edit , buffer, 4); //获取EDIT工具的文本,然后显示在背景中
GUI_DispStringAt(buffer, 130, 80 + 40*i); //感觉可能是这里有问题,但是又实在不知道到底是什么问题,哭。。
}
}
break;
case WM_APP_SHOW_TEXT:
hwin = pMsg->hWinSrc;
WM_HideWin(hwin);
text = 1;
WM_InvalidateWindow(WM_HBKWIN);
break;
default:WM_DefaultProc(pMsg);
break;
}
}
static void _eidtcallback(WM_MESSAGE *pMsg)
{
WM_HWIN hwin;
WM_MESSAGE MSG;
BUTTON_Handle bbutton, sbutton;
EDIT_Handle hedit1, hedit2, hedit3, hedit4, hedit5;
int NCode;
int Id;
WM_HWIN hDlg;
hDlg = pMsg->MsgId;
hwin = pMsg->hWin;
switch (hDlg)
{
case WM_PAINT:
GUI_DrawBitmapEx(&bmjoba, 0, 0, 0, 0, 2500, 1875);
GUI_SetTextMode(GUI_TEXTMODE_TRANS);
GUI_SetFont(&GUI_Font8x16);
GUI_SetColor(GUI_BLACK);
GUI_DispStringAt(name, 130, 40);
GUI_DispStringAt("MEDICINE", 5, 40);
GUI_DispStringAt("LIFESPAN", 5, 80);
GUI_DispStringAt("POSITION", 5, 120);
GUI_DispStringAt("DOSE", 5, 160);
GUI_SetFont(&GUI_Font13B_1);
GUI_DispStringAt("(ALTERNATIVE)", 40, 160);
GUI_SetFont(&GUI_Font8x16x2x2);
GUI_SetColor(GUI_MAGENTA);
GUI_SetTextAlign(GUI_TA_VCENTER | GUI_TA_HCENTER);
GUI_DispStringAt("RECORDING", 160, 10);
break;
case WM_INIT_DIALOG:
FRAMEWIN_SetClientColor(hwin, GUI_INVALID_COLOR); //初始化对话框和小工具
bbutton = WM_GetDialogItem(hwin , GUI_ID_NO);
BUTTON_SetFont(bbutton , &GUI_Font13B_1);
sbutton = WM_GetDialogItem(hwin , GUI_ID_OK);
BUTTON_SetFont(sbutton , &GUI_Font13B_1);
hedit1 = WM_GetDialogItem(hwin, GUI_ID_EDIT1);
hedit2 = WM_GetDialogItem(hwin, GUI_ID_EDIT2);
hedit3 = WM_GetDialogItem(hwin, GUI_ID_EDIT3);
hedit4 = WM_GetDialogItem(hwin, GUI_ID_EDIT4);
hedit5 = WM_GetDialogItem(hwin, GUI_ID_EDIT5);
EDIT_SetTextColor(hedit1, EDIT_CI_ENABELD, GUI_RED);
EDIT_SetTextColor(hedit2, EDIT_CI_ENABELD, GUI_RED);
EDIT_SetTextColor(hedit3, EDIT_CI_ENABELD, GUI_RED);
EDIT_SetTextColor(hedit4, EDIT_CI_ENABELD, GUI_RED);
EDIT_SetTextColor(hedit5, EDIT_CI_ENABELD, GUI_RED);
EDIT_SetMaxLen(hedit1, 10);
EDIT_SetMaxLen(hedit2, 10);
EDIT_SetMaxLen(hedit3, 10);
EDIT_SetMaxLen(hedit4, 30);
EDIT_SetMaxLen(hedit5, 30);
EDIT_SetText(hedit1, "eg : 2016");
EDIT_SetText(hedit2, "eg : 1");
EDIT_SetText(hedit3, "eg : 1");
EDIT_SetText(hedit4, "THE POSITION U SAVE,eg:1");
EDIT_SetText(hedit5, "REST OF THE MEDICINE,eg:10");
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId( pMsg ->hWinSrc);
NCode = pMsg->Data.v;
switch (Id)
{
case GUI_ID_OK: //当按下OK健的时候,对话框窗口关闭
switch (NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
MSG.MsgId = WM_APP_SHOW_TEXT;
MSG.hWinSrc = pMsg->hWin;
WM_SendMessage(WM_HBKWIN , &MSG);
break;
}
break;
case GUI_ID_NO:
switch (NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
WM_HideWin(hwin);
GUI_Clear();
break;
}
break;
}
break;
default:WM_DefaultProc(pMsg);
break;
}
}
最后输入的和结果显示的图片是这样的:
|