57.2 官方WIDGET_Window实例 官方的这个实例很好的演示了window的使用,这个例子在模拟器中的位置:
源码如下(程序中进行了详细的注释):
- #include "GUI.h"
- #include "DIALOG.h"
-
-
- /*********************************************************************
- *
- * _aDialog
- * 对话框创建资源
- */
- static const GUI_WIDGET_CREATE_INFO _aDialog[] = {
- { WINDOW_CreateIndirect, "", 0, 0, 0, 260, 200, 0 },
- { TEXT_CreateIndirect, "Dialog", 0, 80, 5, 100, 20, TEXT_CF_HCENTER },
- { BUTTON_CreateIndirect, "Close", GUI_ID_BUTTON0, 80, 160, 100, 20, 0 }
- };
-
- /*********************************************************************
- *
- * _cbDialog
- * 对话框回调函数
- */
- static void _cbDialog(WM_MESSAGE *pMsg) {
- int NCode;
- int Id;
-
- switch (pMsg->MsgId) {
- case WM_PAINT:
- GUI_SetBkColor(GUI_GREEN);
- GUI_Clear();
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc); // Id of widget
- NCode = pMsg->Data.v; // Notification code
- switch (NCode) {
- case WM_NOTIFICATION_RELEASED: // React only if released
- switch (Id) {
- case GUI_ID_BUTTON0:
- GUI_EndDialog(pMsg->hWin, 0);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
-
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- GUI_Init();
- while(1) {
- GUI_DispStringHCenterAt("WIDGET_Window samplenshows how to use a WINDOW widget", 160, 5);
- /* 阻塞式对话框 */
- GUI_ExecDialogBox(_aDialog, GUI_COUNTOF(_aDialog), _cbDialog, WM_HBKWIN, 30, 30);
- GUI_Clear();
- GUI_DispStringHCenterAt("Dialog has been closed", 160, 5);
- GUI_Delay(1000);
- GUI_Clear();
- }
- }
复制代码
实际显示效果如下:
|