/********************************************************************* * * MESSAGEBOX_Create */ WM_HWIN MESSAGEBOX_Create(const char * sMessage, const char * sCaption, int Flags) { GUI_WIDGET_CREATE_INFO _aDialogCreate[3]; /* 0: FrameWin, 1: Text, 2: Button */ int BorderSize = FRAMEWIN_GetDefaultBorderSize(); /* Default border size of frame window */ int xSizeFrame = MESSAGEBOX_XSIZEOK + 2 * BorderSize + MESSAGEBOX_BORDER * 2; /* XSize of frame window */ int ySizeFrame; /* YSize of frame window */ int x0, y0; /* Position of frame window */ int xSizeMessage; /* Length in pixels of message */ int xSizeCaption; /* Length in pixels of caption */ int ySizeCaption; /* YSize of caption */ int ySizeMessage; /* YSize of message */ WM_HWIN hBox; GUI_RECT Rect; const GUI_FONT GUI_UNI_PTR * pOldFont; /* Zeroinit variables */ memset(_aDialogCreate, 0, sizeof(_aDialogCreate)); /* Get dimension of message */ pOldFont = GUI_SetFont(TEXT_GetDefaultFont()); GUI_GetTextExtend(&Rect, sMessage, 255); xSizeMessage = Rect.x1 - Rect.x0 + MESSAGEBOX_BORDER * 2; ySizeMessage = Rect.y1 - Rect.y0 + 1; if (xSizeFrame < (xSizeMessage + 4 + MESSAGEBOX_BORDER * 2)) { xSizeFrame = xSizeMessage + 4 + MESSAGEBOX_BORDER * 2; } ySizeCaption = GUI_GetYSizeOfFont(FRAMEWIN_GetDefaultFont()); ySizeFrame = ySizeMessage + /* size of message */ MESSAGEBOX_YSIZEOK + /* size of button */ ySizeCaption + /* caption size */ MESSAGEBOX_BORDER * 3 + /* inner border - text, text - button, button - bottom */ BorderSize * 2 + /* top & bottom border */ 1; /* inner border */ /* Get xsize of caption */ xSizeCaption = GUI_GetStringDistX(sCaption); if (xSizeFrame < xSizeCaption + BorderSize * 2) { xSizeFrame = xSizeCaption + BorderSize * 2; } /* Check maximum */ if (xSizeFrame > LCD_GET_XSIZE()) { xSizeFrame = LCD_GET_XSIZE(); } if (ySizeFrame > LCD_GET_YSIZE()) { ySizeFrame = LCD_GET_YSIZE(); } /* Calculate position of framewin */ x0 = GUI_OrgX + (LCD_GET_XSIZE() - xSizeFrame) / 2; y0 = GUI_OrgY + (LCD_GET_YSIZE() - ySizeFrame) / 2; /* restore modified Context */ GUI_SetFont(pOldFont); /* Fill frame win resource */ _aDialogCreate[0].pfCreateIndirect = FRAMEWIN_CreateIndirect; _aDialogCreate[0].pName = sCaption; _aDialogCreate[0].x0 = x0; _aDialogCreate[0].y0 = y0; _aDialogCreate[0].xSize = xSizeFrame; _aDialogCreate[0].ySize = ySizeFrame; if (Flags & GUI_MESSAGEBOX_CF_MOVEABLE) { _aDialogCreate[0].Flags = FRAMEWIN_CF_MOVEABLE; } /* Fill text resource */ _aDialogCreate[1].pfCreateIndirect = TEXT_CreateIndirect; _aDialogCreate[1].pName = sMessage; _aDialogCreate[1].x0 = (xSizeFrame - xSizeMessage - BorderSize * 2) / 2; _aDialogCreate[1].y0 = MESSAGEBOX_BORDER; _aDialogCreate[1].xSize = xSizeMessage; _aDialogCreate[1].ySize = ySizeMessage; _aDialogCreate[1].Para = GUI_TA_TOP | GUI_TA_HCENTER; /* Fill button resource */ _aDialogCreate[2].pfCreateIndirect = BUTTON_CreateIndirect; _aDialogCreate[2].pName = "OK"; _aDialogCreate[2].Id = GUI_ID_OK; _aDialogCreate[2].x0 = (xSizeFrame - MESSAGEBOX_XSIZEOK - BorderSize * 2) / 2; _aDialogCreate[2].y0 = MESSAGEBOX_BORDER * 2 + ySizeMessage; _aDialogCreate[2].xSize = MESSAGEBOX_XSIZEOK; _aDialogCreate[2].ySize = MESSAGEBOX_YSIZEOK; /* Create dialog */ hBox = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), MESSAGEBOX_Callback, 0, 0, 0); if (Flags & GUI_MESSAGEBOX_CF_MODAL) { WM_MakeModal(hBox); } return hBox; }
/********************************************************************* * * MainTask */ void MainTask(void) { TREEVIEW_ITEM_Handle hNode; WM_HWIN hTree; int xSize; int ySize; int yPos; int r; int TimeStart; int TimeUsed; int ySizeText; U32 BytesFree; U32 BytesUsed; char acBuffer[(TREEVIEW_DEPTH << 1) + 1]; char acNumNodes[30] = "Nodes: "; char acNumLeaves[30] = "Leaves: "; char acNumTotal[30] = "Total: "; char acTimeUsed[30] = "Time: "; char acBytesUsed[30] = "Memory: "; // // Initialize emWin // WM_SetCreateFlags(WM_CF_MEMDEV); GUI_Init(); xSize = LCD_GetXSize(); ySize = LCD_GetYSize(); // // Set defaults for background and widgets // WM_SetDesktopColor(GUI_BLACK); SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX); SCROLLBAR_SetDefaultWidth(20); SCROLLBAR_SetThumbSizeMin(25); TEXT_SetDefaultFont(GUI_FONT_6X8); // // Draw info message before creating the widgets // GUI_DrawGradientV(0, 0, xSize - 1, ySize - 1, GUI_BLUE, GUI_BLACK); GUI_SetFont(GUI_FONT_20F_ASCII); GUI_DispStringHCenterAt("Filling TREEVIEW widget...", xSize >> 1, ySize / 3); GUI_X_Delay(1000); // // Create TREEVIEW // hTree = TREEVIEW_CreateEx(0, 0, xSize, ySize, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TREEVIEW0); TREEVIEW_SetAutoScrollV(hTree, 1);//管理自动使用垂直滚动条。 TREEVIEW_SetSelMode(hTree, TREEVIEW_SELMODE_ROW); // // Fill TREEVIEW // hNode = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Tree"); BytesFree = GUI_ALLOC_GetNumFreeBytes(); TimeStart = GUI_GetTime(); r = _FillNode(hTree, hNode, NUM_CHILD_NODES, NUM_CHILD_ITEMS, TREEVIEW_DEPTH, TREEVIEW_DEPTH, acBuffer, acBuffer); TimeUsed = GUI_GetTime() - TimeStart; BytesUsed = BytesFree - GUI_ALLOC_GetNumFreeBytes(); if (r) { // // Error message // WM_DeleteWindow(hTree); GUI_MessageBox("Error", "Not enough memory available!", 0); } else { // // Show result // yPos = 20; ySizeText = GUI_GetYDistOfFont( TEXT_GetDefaultFont()) + 5; _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumNodes, _NumNodes); _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumLeaves, _NumLeaves); _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumTotal, _NumNodes + _NumLeaves); _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acTimeUsed, TimeUsed); _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acBytesUsed, BytesUsed); WM_SetFocus(hTree); } while (1) { GUI_Delay(100); } }