19.1.7 第七步:添加主函数
- #include "includes.h"
- #include "MainTask.h"
-
-
- extern GUI_CONST_STORAGE GUI_FONT GUI_FontHZ48;
-
- /*
- *********************************************************************************************************
- * 对话框信息
- *********************************************************************************************************
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect, "armfly", 0, 0, 0, 800,480,FRAMEWIN_CF_MOVEABLE,0},
- { BUTTON_CreateIndirect, "安富莱电子armfly", GUI_ID_BUTTON0, 40,320,700,100,0,0},
- { BUTTON_CreateIndirect, "世界人民欢迎你Eric2013", GUI_ID_BUTTON1, 40,200,700,100,0,0},
- { TEXT_CreateIndirect, "armfly安富莱电子armfly", GUI_ID_TEXT0, 5, 10, 200, 33, 0,0},
- { TEXT_CreateIndirect, "armfly安富莱电子armfly", GUI_ID_TEXT1, 5, 40,200, 33, 0,0},
- { TEXT_CreateIndirect, "安富莱电子armfly", GUI_ID_TEXT2, 5, 80,360, 72, 0,0},
- };
-
- /*
- *********************************************************************************************************
- * 函 数 名: PaintDialog
- * 功能说明: 重绘
- * 形 参:pMsg 消息指针
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void PaintDialog(WM_MESSAGE * pMsg)
- {
- WM_HWIN hWin = pMsg->hWin;
- }
-
- /*
- *********************************************************************************************************
- * 函 数 名: InitDialog
- * 功能说明: 对话框初始化
- * 形 参:pMsg 消息指针
- * 返 回 值: 无
- *********************************************************************************************************
- */
- void InitDialog(WM_MESSAGE * pMsg)
- {
- WM_HWIN hWin = pMsg->hWin;
- //
- //FRAMEWIN
- //
- FRAMEWIN_SetFont(hWin,&GUI_Font32B_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,35);
- //
- //GUI_ID_BUTTON0
- //
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON0),&GUI_FontHZ48);
- BUTTON_SetFont(WM_GetDialogItem(hWin,GUI_ID_BUTTON1),&GUI_FontHZ48);
- //
- //GUI_ID_TEXT0
- //
- TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT0), GUI_RED);
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT0),&GUI_FontHZ12);
- TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT1), GUI_GREEN);
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT1),&GUI_FontHZ16);
- TEXT_SetTextColor(WM_GetDialogItem(hWin,GUI_ID_TEXT2), GUI_BLUE);
- TEXT_SetFont(WM_GetDialogItem(hWin,GUI_ID_TEXT2),&GUI_FontHZ24);
- }
-
- /*
- *********************************************************************************************************
- * 函 数 名: _cbCallback
- * 功能说明: 对话框回调函数
- * 形 参: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;
- 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
- * 功能说明: GUI主函数
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- 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_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
- while(1)
- {
- GUI_Delay(10);
- }
- }
复制代码
实际显示效果如下:
特别注意,如果使用的是800*480分辨率的屏可以完全显示出来,如果是小于这个分辨率的屏只能显示出一部分,大家可以按照上面的设计方法做一个适合自己屏大小的显示或者直接拖动这个对话框即可。
|