40.4 对话框上使用按钮控件 通过uCGUIBulder建立一个如下的界面(分辨率480*272):
同时使能BUTTON0和BUTTON1的三个通知代码消息:
这里我们仅使用按钮的CLICKED消息,通过这两个按钮实现对话框中背景颜色的改变。源代码如下(可以直接的复制到开发板或者模拟器上面运行):
- #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"
-
- /*********************************************************************
- *
- * static data
- *
- **********************************************************************
- */
- GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW}; (1)
- static char BackColor;
-
- /*********************************************************************
- *
- * 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},
- { BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 52, 93, 110,30, 0,0},
- { BUTTON_CreateIndirect, "BUTTON1", GUI_ID_BUTTON1, 289,90, 117,33, 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)(2)
- {
- WM_HWIN hWin = pMsg->hWin;
- GUI_SetBkColor(_acColor[BackColor]);
- GUI_Clear();
- }
-
- /*****************************************************************
- ** 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_Font24B_ASCII);
- FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER);
- FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
- FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
- FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
- FRAMEWIN_SetTitleHeight(hWin,30);
- //
- //GUI_ID_BUTTON0
- //
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),&GUI_Font24B_ASCII); (3)
- //
- //GUI_ID_BUTTON1
- //
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),&GUI_Font24B_ASCII);
-
- /* 默认颜色取*/
- BackColor = 0;
- }
-
- /*********************************************************************
- *
- * 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;
- case GUI_ID_BUTTON0:
- switch(NCode)
- {
- case WM_NOTIFICATION_CLICKED:(4)
- BackColor++;
- if (BackColor == 3)
- {
- BackColor = 0;
- }
- WM_InvalidateWindow(hWin);
- break;
- case WM_NOTIFICATION_RELEASED:
-
- break;
- case WM_NOTIFICATION_MOVED_OUT:
-
- break;
- }
- break;
- case GUI_ID_BUTTON1:
- switch(NCode)
- {
- case WM_NOTIFICATION_CLICKED:(5)
- BackColor--;
- if (BackColor < 0)
- {
- BackColor = 2;
- }
- WM_InvalidateWindow(hWin);
- break;
- case WM_NOTIFICATION_RELEASED:
-
- break;
- case WM_NOTIFICATION_MOVED_OUT:
-
- break;
- }
- 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);(6)
- }
1. 对话框用户区可选的三种背景颜色。
2. 对话框回调函数中的重绘消息要执行的函数。
3. 设置按钮的字体。在uCGUIBulder中可以在这里设置:
4. 设置按钮按下后要处理的消息。
5. 同上,处理按钮按下后要处理的消息。
6. 创建阻塞式对话框。
这个程序的实际显示效果如下(480*272分辨率):
40.4 对话框上使用按钮控件 通过uCGUIBulder建立一个如下的界面(分辨率480*272):
同时使能BUTTON0和BUTTON1的三个通知代码消息:
这里我们仅使用按钮的CLICKED消息,通过这两个按钮实现对话框中背景颜色的改变。源代码如下(可以直接的复制到开发板或者模拟器上面运行):
- #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"
-
- /*********************************************************************
- *
- * static data
- *
- **********************************************************************
- */
- GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW}; (1)
- static char BackColor;
-
- /*********************************************************************
- *
- * 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},
- { BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 52, 93, 110,30, 0,0},
- { BUTTON_CreateIndirect, "BUTTON1", GUI_ID_BUTTON1, 289,90, 117,33, 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)(2)
- {
- WM_HWIN hWin = pMsg->hWin;
- GUI_SetBkColor(_acColor[BackColor]);
- GUI_Clear();
- }
-
- /*****************************************************************
- ** 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_Font24B_ASCII);
- FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER);
- FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0);
- FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1);
- FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2);
- FRAMEWIN_SetTitleHeight(hWin,30);
- //
- //GUI_ID_BUTTON0
- //
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),&GUI_Font24B_ASCII); (3)
- //
- //GUI_ID_BUTTON1
- //
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),&GUI_Font24B_ASCII);
-
- /* 默认颜色取*/
- BackColor = 0;
- }
-
- /*********************************************************************
- *
- * 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;
- case GUI_ID_BUTTON0:
- switch(NCode)
- {
- case WM_NOTIFICATION_CLICKED:(4)
- BackColor++;
- if (BackColor == 3)
- {
- BackColor = 0;
- }
- WM_InvalidateWindow(hWin);
- break;
- case WM_NOTIFICATION_RELEASED:
-
- break;
- case WM_NOTIFICATION_MOVED_OUT:
-
- break;
- }
- break;
- case GUI_ID_BUTTON1:
- switch(NCode)
- {
- case WM_NOTIFICATION_CLICKED:(5)
- BackColor--;
- if (BackColor < 0)
- {
- BackColor = 2;
- }
- WM_InvalidateWindow(hWin);
- break;
- case WM_NOTIFICATION_RELEASED:
-
- break;
- case WM_NOTIFICATION_MOVED_OUT:
-
- break;
- }
- 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);(6)
- }
1. 对话框用户区可选的三种背景颜色。
2. 对话框回调函数中的重绘消息要执行的函数。
3. 设置按钮的字体。在uCGUIBulder中可以在这里设置:
4. 设置按钮按下后要处理的消息。
5. 同上,处理按钮按下后要处理的消息。
6. 创建阻塞式对话框。
这个程序的实际显示效果如下(480*272分辨率):
举报