43.3 对话框上使用编辑框控件 用uCGUIBulder4.0建立一个如下的界面(分辨率480*272):
通过这个例子主要是显示一下编辑框支持的五种显示方式,设置的位置如下:
源代码如下(可以直接复制到模拟器或者开发板上面显示):
- #include
- #include "GUI.h"
- #include "DIALOG.h"
- #include "WM.h"
- #include "BUTTON.h"
- #include "CHECKBOX.h"
- #include "DROPDOWN.h"
- #include "EDIT.h"
- #include "FRAMEWIN.h"
- #include "LISTBOX.h"
- #include "MULTIEDIT.h"
- #include "RADIO.h"
- #include "SLIDER.h"
- #include "TEXT.h"
- #include "PROGBAR.h"
- #include "SCROLLBAR.h"
- #include "LISTVIEW.h"
-
- /*********************************************************************
- *
- * Dialog resource
- *
- * This table conatins the info required to create the dialog.
- * It has been created by ucGUIbuilder.
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect, "armfly", 0, 0, 0, 480,272,FRAMEWIN_CF_MOVEABLE,0},
- { EDIT_CreateIndirect, "armfly", GUI_ID_EDIT0, 239,36, 100,21, 0,0},
- { TEXT_CreateIndirect, "TextMode", GUI_ID_TEXT0, 81, 36, 106,24, 0,0},
- { TEXT_CreateIndirect, "FloatMode", GUI_ID_TEXT4, 81, 199,118,24, 0,0},
- { TEXT_CreateIndirect, "DecMode", GUI_ID_TEXT3, 81, 158,94, 24, 0,0},
- { TEXT_CreateIndirect, "BinMode", GUI_ID_TEXT2, 81, 117,94, 24, 0,0},
- { TEXT_CreateIndirect, "HexMode", GUI_ID_TEXT1, 81, 73, 94, 24, 0,0},
- { EDIT_CreateIndirect, "FFFF", GUI_ID_EDIT1, 239,73, 100,21, 0,0},
- { EDIT_CreateIndirect, "11110000", GUI_ID_EDIT2, 239,120,100,21, 0,0},
- { EDIT_CreateIndirect, "128", GUI_ID_EDIT3, 239,163,100,21, 0,0},
- { EDIT_CreateIndirect, "12.123456", GUI_ID_EDIT4, 239,199,100,21, 0,0}
- };
-
- /*****************************************************************
- ** FunctionName:void PaintDialog(WM_MESSAGE * pMsg)
- ** Function: to initialize the Dialog items
- **
- ** call this function in _cbCallback --> WM_PAINT
- *****************************************************************/
-
- void PaintDialog(WM_MESSAGE * pMsg)
- {
- WM_HWIN hWin = pMsg->hWin;
-
- }
-
- /*****************************************************************
- ** FunctionName:void InitDialog(WM_MESSAGE * pMsg)
- ** Function: to initialize the Dialog items
- **
- ** call this function in _cbCallback --> WM_INIT_DIALOG
- *****************************************************************/
-
- void InitDialog(WM_MESSAGE * pMsg)
- {
- WM_HWIN hWin = pMsg->hWin;
- //
- //FRAMEWIN
- //
- FRAMEWIN_SetFont(hWin,&GUI_Font32B_ASCII);
- FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
- FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
- FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
- FRAMEWIN_SetTitleHeight(hWin,35);
- //
- //GUI_ID_EDIT0
- //
- EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT0),&GUI_Font16B_ASCII);
- EDIT_SetText(WM_GetDialogItem(hWin,GUI_ID_EDIT0),"armfly");
- //
- //GUI_ID_TEXT0
- //
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT0),&GUI_Font24B_ASCII);
- //
- //GUI_ID_TEXT4
- //
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT4),&GUI_Font24B_ASCII);
- //
- //GUI_ID_TEXT3
- //
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT3),&GUI_Font24B_ASCII);
- //
- //GUI_ID_TEXT2
- //
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT2),&GUI_Font24B_ASCII);
- //
- //GUI_ID_TEXT1
- //
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT1),&GUI_Font24B_ASCII);
- //
- //GUI_ID_EDIT1
- //
- EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT1),&GUI_Font16B_ASCII);
- EDIT_SetHexMode(WM_GetDialogItem(hWin,GUI_ID_EDIT1),65535,0,255);(1)
- //
- //GUI_ID_EDIT2
- //
- EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT2),&GUI_Font16B_ASCII);
- EDIT_SetBinMode(WM_GetDialogItem(hWin,GUI_ID_EDIT2),240,0,255);(2)
- //
- //GUI_ID_EDIT3
- //
- EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT3),&GUI_Font16B_ASCII);
- EDIT_SetDecMode(WM_GetDialogItem(hWin,GUI_ID_EDIT3),128,0,255,0,0); (3)
- //
- //GUI_ID_EDIT4
- //
- EDIT_SetFont(WM_GetDialogItem(hWin,GUI_ID_EDIT4),&GUI_Font16B_ASCII);
- EDIT_SetFloatMode(WM_GetDialogItem(hWin,GUI_ID_EDIT4),12.12346,0,255,6,0); (4)
-
- }
-
- /*********************************************************************
- *
- * Dialog callback routine
- */
- static void _cbCallback(WM_MESSAGE * pMsg)
- {
- int NCode, Id;
- WM_HWIN hWin = pMsg->hWin;
- switch (pMsg->MsgId)
- {
- case WM_PAINT:
- PaintDialog(pMsg);
- break;
- case WM_INIT_DIALOG:
- InitDialog(pMsg);
- break;
- case WM_KEY:
- switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
- {
- case GUI_KEY_ESCAPE:
- GUI_EndDialog(hWin, 1);
- break;
- case GUI_KEY_ENTER:
- GUI_EndDialog(hWin, 0);
- break;
- }
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch (Id)
- {
- case GUI_ID_OK:
- if(NCode==WM_NOTIFICATION_RELEASED)
- GUI_EndDialog(hWin, 0);
- break;
- case GUI_ID_CANCEL:
- if(NCode==WM_NOTIFICATION_RELEASED)
- GUI_EndDialog(hWin, 0);
- break;
-
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * MainTask
- *
- **********************************************************************
- */
- void MainTask(void)
- {
- GUI_Init();
- WM_SetDesktopColor(GUI_WHITE); /* Automacally update desktop window */
- WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */
- PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
- FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
- PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
- BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
- CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX);
- DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX);
- SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
- SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX);
- HEADER_SetDefaultSkin(HEADER_SKIN_FLEX);
- RADIO_SetDefaultSkin(RADIO_SKIN_FLEX);
- GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
- }
复制代码
1. 设置16进制显示。 2. 设置2进制显示。 3. 设置10进制显示。 4. 设置浮点数显示。 实际的显示效果如下:
|