ucgui的BUTTON控件问题
发布网友
发布时间:2022-05-02 12:18
我来回答
共1个回答
热心网友
时间:2022-06-20 01:14
#include <stddef.h>
#include "GUI.h"
#include "DIALOG.h"
#include "WM.h"
#include "BUTTON.h"
#include "FRAMEWIN.h"
/*主界面的资源链表*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Caption", 0, 0, 0, 320,240,FRAMEWIN_CF_MOVEABLE,0},
{ BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 84, 55, 134,56, 0,0}
};
/*按钮按下之后的资源链表*/
static const GUI_WIDGET_CREATE_INFO _aButtonCreate[] = {
{ FRAMEWIN_CreateIndirect, "Caption", 0, 0, 0, 320,240,FRAMEWIN_CF_MOVEABLE,0},
};
/*主界面的绘制函数*/
void PaintDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
}
/*主界面的初始化函数,初始化标题栏的最大化,最小化,关闭按钮*/
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);
}
/*按钮弹出界面的回调函数*/
static void _cbButtonCallback(WM_MESSAGE * pMsg)
{
WM_HWIN hWin = pMsg->hWin;
switch (pMsg->MsgId)
{
case WM_INIT_DIALOG:
InitDialog(pMsg);
break;
default:
WM_DefaultProc(pMsg);
}
}
/*主界面的回调函数*/
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;
#if 0
//这个是接收键盘上的按键的相应
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;
#endif
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (Id)
{
case GUI_ID_BUTTON0:
if(NCode==WM_NOTIFICATION_RELEASED)
{
GUI_ExecDialogBox(_aButtonCreate, GUI_COUNTOF(_aButtonCreate), &_cbButtonCallback, 0, 0, 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 */
while(1)
{
GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
}
}
关于界面的创建可以用ucguibuilder来创建,它会自动生成代码;然后自己根据所需修改即可。