大学生
最后登录1970-1-1
在线时间 小时
注册时间2013-5-1
|
说明: (野火团队原创教程,未经许可禁止转载)
VC6.0 emWin5.20下载地址
http://pan.baidu.com/share/link?shareid=641741&uk=286563520
uCGUIBulder 4.0
http://pan.baidu.com/share/link?shareid=641752&uk=286563520
一. 实验说明
一共使用了以下几个控件
RADIO, TEXT, BUTTON, Frame. 这几个控件都是依附在对话框上面的。
二. 例程讲解
/*
----------------------------------------------------------------------
File : DIALOG_Count.c
Purpose : Shows a dialog which is continously counting
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Counting...", 0, 30, 90, 260, 140, FRAMEWIN_CF_MOVEABLE },
{ TEXT_CreateIndirect, "00", GUI_ID_TEXT0, 10, 10, 120, 80 },
{ RADIO_CreateIndirect, "", GUI_ID_RADIO0, 150, 10, 100, 80, 0, 4 },
{ BUTTON_CreateIndirect, "OK", GUI_ID_OK, 10, 100, 60, 18 },
{ BUTTON_CreateIndirect, "Cancel", GUI_ID_CANCEL, 180, 100, 60, 18 },
};
static const char * _apLabel[] = {
{"GUI_FontFD32"},
{"GUI_FontFD48"},
{"GUI_FontFD64"},
{"GUI_FontFD80"},
};
static const GUI_FONT * _apFont[] = {
&GUI_FontD32,
&GUI_FontD48,
&GUI_FontD64,
&GUI_FontD80
};
static const char * _asExplain[] = {
{"Please use the RADIO buttons to select"},
{"the big digit font used for counting."}
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _SetFont
*/
static void _SetFont(WM_HWIN hDlg) {
WM_HWIN hItem;
int Index;
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
Index = RADIO_GetValue(hItem);
hItem = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
TEXT_SetFont(hItem, _apFont[Index]);
}
/*********************************************************************
*
* _cbBkWindow
*/
static void _cbBkWindow(WM_MESSAGE * pMsg) {
int i;
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_BLUE);
GUI_Clear();
GUI_SetColor(GUI_WHITE);
GUI_SetFont(&GUI_Font24_ASCII);
GUI_DispStringHCenterAt("Counting Sample", 160, 5);
GUI_SetFont(&GUI_Font8x16);
for (i = 0; i < GUI_COUNTOF(_asExplain); i++) {
GUI_DispStringAt(_asExplain, 5, 40 + i * 16);
}
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* _cbCallback
*/
static void _cbCallback(WM_MESSAGE * pMsg) {
int i;
int NCode, Id;
WM_HWIN hDlg, hItem;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = WM_GetDialogItem(hDlg, GUI_ID_RADIO0);
for (i = 0; i < GUI_COUNTOF(_apLabel); i++) {
/* 显示文本,句柄,文本,第几个单选框 */
RADIO_SetText(hItem, _apLabel, i);
}
_SetFont(hDlg);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
NCode = pMsg->Data.v; /* Notification code */
switch (NCode) {
case WM_NOTIFICATION_VALUE_CHANGED: /* Value has changed */
/* 检测到单选框变换,更改字体 */
_SetFont(hDlg);
break;
case WM_NOTIFICATION_RELEASED: /* React only if released */
if (Id == GUI_ID_OK) { /* OK Button */
GUI_EndDialog(hDlg, 0);
}
if (Id == GUI_ID_CANCEL) { /* Cancel Button */
GUI_EndDialog(hDlg, 1);
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Exported code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
int Value = 0;
WM_HWIN hDlgFrame;
GUI_Init();
WM_SetCallback(WM_HBKWIN, _cbBkWindow);
WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */
hDlgFrame = 0;
while(1) {
WM_HWIN hDlg, hText;
char acText[3] = {0};
GUI_Delay(150);
/* 检测是否创建,创建了就不会再执行,关闭后还会重新的创建 */
if (!WM_IsWindow(hDlgFrame)) {
hDlgFrame = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}
Value = (Value + 1) % 100;
acText[0] = '0' + Value / 10;
acText[1] = '0' + Value % 10;
/* 得到句柄 */
hDlg = WM_GetClientWindow(hDlgFrame);
hText = WM_GetDialogItem(hDlg, GUI_ID_TEXT0);
/* 显示文本 */
TEXT_SetText(hText, acText);
}
}
三. 如何在野火开发板上面跑这个程序
1. 在火哥的开发板里面找到这个UCGUI DEMO的横屏或竖屏的程序,
将上面的代码复制到下面这个文件里面,覆盖掉原来的文件,就可
以正常的运行了。
|
|