这次来个简单的实例。我们来做一个计算器。
首先打开ucguibuilder,设计界面。(注意,我们用ucguibuilder只是做界面的,功能得自己写的哦)
界面制作如下:(有些丑,后面可以用皮肤,现在就将就的看着吧)
跟之前一样放一份ucguibuilder自动生成的代码上来,注意,我这边没有更改button的id,直接复制粘帖的控件,所以一样。等下自己更改就行了。
/*
******************************************************************
** uCGUIBuilder **
** Version: 4.0.0.0 **
** 2012 / 04 **
** CpoyRight to: wyl **
** Email:ucguibuilder@163.com **
** This text was Created by uCGUIBuilder **
******************************************************************/
#include <stddef.h>
#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"
//EventsFunctionList
//EndofEventsFunctionList
/*********************************************************************
*
* static data
*
**********************************************************************
*/
#define GUI_ID_BUTTON10 GUI_ID_USER+1
/*********************************************************************
*
* 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, "Caption", 0, 0, 0, 320,240,FRAMEWIN_CF_MOVEABLE,0},
{ EDIT_CreateIndirect, NULL, GUI_ID_EDIT0, 3, 3, 222,32, 0,0},
{ BUTTON_CreateIndirect, "7", GUI_ID_BUTTON0, 3, 41, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "4", GUI_ID_BUTTON1, 3, 86, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "1", GUI_ID_BUTTON2, 3, 135,70, 39, 0,0},
{ BUTTON_CreateIndirect, "0", GUI_ID_BUTTON3, 3, 183,70, 39, 0,0},
{ BUTTON_CreateIndirect, "8", GUI_ID_BUTTON0, 79, 41, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "5", GUI_ID_BUTTON1, 79, 86, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "2", GUI_ID_BUTTON2, 79, 135,70, 39, 0,0},
{ BUTTON_CreateIndirect, ".", GUI_ID_BUTTON3, 79, 183,70, 39, 0,0},
{ BUTTON_CreateIndirect, "9", GUI_ID_BUTTON0, 155,41, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "6", GUI_ID_BUTTON1, 155,86, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "3", GUI_ID_BUTTON2, 155,135,70, 39, 0,0},
{ BUTTON_CreateIndirect, "=", GUI_ID_BUTTON3, 155,183,70, 39, 0,0},
{ BUTTON_CreateIndirect, "+", GUI_ID_BUTTON0, 244,41, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "-", GUI_ID_BUTTON1, 244,86, 70, 39, 0,0},
{ BUTTON_CreateIndirect, "*", GUI_ID_BUTTON2, 244,135,70, 39, 0,0},
{ BUTTON_CreateIndirect, "/", GUI_ID_BUTTON3, 244,183,70, 39, 0,0},
{ BUTTON_CreateIndirect, "CLR", GUI_ID_BUTTON10, 244,3, 70, 32, 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_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
//
//GUI_ID_EDIT0
//
EDIT_SetText(WM_GetDialogItem(hWin,GUI_ID_EDIT0),"EDIT0");
}
/*********************************************************************
*
* 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);
while(1)
{
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}
}
这份代码放到模拟器里是能够显示了,但是没有功能而已,所以接下来我们给他增加功能。同样去除不必要的代码,增加功能代码,代码如下: