|
本人萌新。使用STemwin在Window中生成了四个图标,每个图标可以切换到其他Window。每次切换我都使用WM_DeleteWindow()把之前的Window删除。但是运行时发现两个界面互相切换时到了第五次就卡住了。使用GUI_ALLOC_GetNumFreeBytes(),发现内存并没有减少。这是啥原因啊?  。各位大佬,江湖救急。。。附代码如下:
#include "icontest.h"
/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.40 *
* Compiled Jun 22 2017, 10:13:26 *
* (c) 2017 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
// USER START (Optionally insert additional includes)
// USER END
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_ICONVIEW_0 (GUI_ID_USER + 0x01)
#define ID_ICONVIEW_1 (GUI_ID_USER + 0x02)
#define ID_ICONVIEW_2 (GUI_ID_USER + 0x03)
#define ID_ICONVIEW_3 (GUI_ID_USER + 0x04)
// USER START (Optionally insert additional defines)
#define RECOMMENDED_MEMORY (1024L * 20)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
typedef struct{
const GUI_BITMAP *pBitmap; //app图标
const char *pText; //app图标名字
}BITMAP_ITEM;
static const BITMAP_ITEM BitmapItemTab1[]={
{&bmtiming, "Time"},
{&bmwalk, "Walk"},
{&bmsos, "SOS" },
{&bmtalk, "Talk"},
};
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 240, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_0, 0, 0, 120, 120, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_1, 120, 0, 120, 120, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_2, 0, 120, 120, 120, 0, 0x0, 0 },
{ ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_3, 120, 120, 120, 120, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbIconDialog(WM_MESSAGE * pMsg) {
static int NCode;
static int Id;
// USER START (Optionally insert additional variables)
static ICONVIEW_Handle IconviewWin;
//int i;
// USER END
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
break;
case WM_INIT_DIALOG:
IconviewWin=WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_0);
ICONVIEW_SetFont(IconviewWin,&GUI_Font8_ASCII);
ICONVIEW_SetBkColor(IconviewWin,ICONVIEW_CI_BK,GUI_BLACK);
ICONVIEW_SetIconAlign(IconviewWin,ICONVIEW_IA_LEFT|ICONVIEW_IA_TOP);
ICONVIEW_AddBitmapItem(IconviewWin,BitmapItemTab1[0].pBitmap,BitmapItemTab1[0].pText);
IconviewWin=WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_1);
ICONVIEW_SetFont(IconviewWin,&GUI_Font16_ASCII);
ICONVIEW_SetBkColor(IconviewWin,ICONVIEW_CI_BK,GUI_BLACK);
ICONVIEW_SetIconAlign(IconviewWin,ICONVIEW_IA_LEFT|ICONVIEW_IA_TOP);
ICONVIEW_AddBitmapItem(IconviewWin,BitmapItemTab1[1].pBitmap,BitmapItemTab1[1].pText);
IconviewWin=WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_2);
ICONVIEW_SetFont(IconviewWin,&GUI_Font16_ASCII);
ICONVIEW_SetBkColor(IconviewWin,ICONVIEW_CI_BK,GUI_BLACK);
ICONVIEW_SetIconAlign(IconviewWin,ICONVIEW_IA_LEFT|ICONVIEW_IA_TOP);
ICONVIEW_AddBitmapItem(IconviewWin,BitmapItemTab1[2].pBitmap,BitmapItemTab1[2].pText);
IconviewWin=WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_3);
ICONVIEW_SetFont(IconviewWin,&GUI_Font16_ASCII);
ICONVIEW_SetBkColor(IconviewWin,ICONVIEW_CI_BK,GUI_BLACK);
ICONVIEW_SetIconAlign(IconviewWin,ICONVIEW_IA_LEFT|ICONVIEW_IA_TOP);
ICONVIEW_AddBitmapItem(IconviewWin,BitmapItemTab1[3].pBitmap,BitmapItemTab1[3].pText);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_ICONVIEW_0: // Notifications sent by 'Iconview'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// WM_DeleteWindow(pMsg->hWin);
// pMsg->hWin=0;
GUI_EndDialog(pMsg->hWin,0);
WM_DeleteWindow(pMsg->hWin);
main_time_set();
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_1: // Notifications sent by 'Iconview'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// WM_DeleteWindow(pMsg->hWin);
// pMsg->hWin=0;
GUI_EndDialog(pMsg->hWin,0);
WM_DeleteWindow(pMsg->hWin);
MainGraphTask();
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_2: // Notifications sent by 'Iconview'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
WM_HideWindow(pMsg->hWin);
messageboxtest();
WM_ShowWindow(pMsg->hWin);
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_ICONVIEW_3: // Notifications sent by 'Iconview'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_MOVED_OUT:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SCROLL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_SEL_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
case WM_DELETE:
break;
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
static WM_HWIN CreateIconWindow(void) {
static WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbIconDialog, WM_HBKWIN, 0, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
void icontest(void)
{
static WM_HWIN IhWin;
if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
GUI_ErrorOut("Not enough memory available.");
return;
}
IhWin = CreateIconWindow();
while(1)
{
GUI_Delay(100);
}
}
// USER END
/*************************** End of file ****************************/
///*********************************************************************
//* *
//* SEGGER Microcontroller GmbH & Co. KG *
//* Solutions for real time microcontroller applications *
//* *
//**********************************************************************
//* *
//* C-file generated by: *
//* *
//* GUI_Builder for emWin version 5.40 *
//* Compiled Jun 22 2017, 10:13:26 *
//* (c) 2017 Segger Microcontroller GmbH & Co. KG *
//* *
//**********************************************************************
//* *
//* Internet: www.segger.com Support: support@segger.com *
//* *
//**********************************************************************
//*/
//// USER START (Optionally insert additional includes)
//// USER END
//#include "DIALOG.h"
///*********************************************************************
//*
//* Defines
//*
//**********************************************************************
//*/
//#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
//#define ID_ICONVIEW_0 (GUI_ID_USER + 0x01)
//// USER START (Optionally insert additional defines)
//// USER END
///*********************************************************************
//*
//* Static data
//*
//**********************************************************************
//*/
//// USER START (Optionally insert additional static data)
//typedef struct{
// const GUI_BITMAP *pBitmap; //app图标
// const char *pText; //app图标名字
//}BITMAP_ITEM;
//static const BITMAP_ITEM BitmapItemTab1[]={
//
// {&bmstepcount, "Step"},
// {&bmlocation, "Location"},
// {&bmpill, " ill" },
// {&bmstepcount, "Setting"},
//};
//// USER END
///*********************************************************************
//*
//* _aDialogCreate
//*/
//static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
// { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 240, 0, 0x0, 0 },
// { ICONVIEW_CreateIndirect, "Iconview", ID_ICONVIEW_0, 0, 0, 240, 240, 0, 0x0, 0 },
// // USER START (Optionally insert additional widgets)
// // USER END
//};
///*********************************************************************
//*
//* Static code
//*
//**********************************************************************
//*/
//// USER START (Optionally insert additional static code)
//// USER END
///*********************************************************************
//*
//* _cbDialog
//*/
//static void _cbDialog(WM_MESSAGE * pMsg) {
// int NCode;
// int Id;
// // USER START (Optionally insert additional variables)
// static int Iconview0_Sel;
// ICONVIEW_Handle IconviewWin;
// int i;
// // USER END
// switch (pMsg->MsgId) {
//
// case WM_PAINT:
// GUI_SetBkColor(GUI_BLACK);
// GUI_Clear();
// break;
//
// case WM_INIT_DIALOG:
// IconviewWin=WM_GetDialogItem(pMsg->hWin,ID_ICONVIEW_0);
// ICONVIEW_SetFont(IconviewWin,&GUI_Font16_ASCII);
// ICONVIEW_SetBkColor(IconviewWin,ICONVIEW_CI_SEL,GUI_WHITE|0X70000000);
//// ICONVIEW_SetSpace(IconviewWin,GUI_COORD_X,10);
//// ICONVIEW_SetSpace(IconviewWin,GUI_COORD_Y,10);
// ICONVIEW_SetIconAlign(IconviewWin,ICONVIEW_IA_LEFT |ICONVIEW_IA_TOP);
// for(i=0;i<(GUI_COUNTOF(BitmapItemTab1));i++)
// {
// ICONVIEW_AddBitmapItem(IconviewWin,BitmapItemTab1.pBitmap,BitmapItemTab1.pText);
// }
// break;
//
// case WM_NOTIFY_PARENT:
// Id = WM_GetId(pMsg->hWinSrc);
// NCode = pMsg->Data.v;
// switch(Id) {
// case ID_ICONVIEW_0: // Notifications sent by 'Iconview'
// switch(NCode) {
// case WM_NOTIFICATION_CLICKED:
// // USER START (Optionally insert code for reacting on notification message)
// // USER END
// break;
// case WM_NOTIFICATION_RELEASED:
// // USER START (Optionally insert code for reacting on notification message)
// Iconview0_Sel=ICONVIEW_GetSel(pMsg->hWinSrc);
// switch(Iconview0_Sel)
// {
// case 0: //APP0
// StepcountApp(); //创建BagAPP
// break;
// case 1: //APP1
// LocationApp(); //创建BookAPP
// break;
// case 2: //APP2
// PillApp(); //创建BookshAPP
// break;
// case 3: //APP3
// SettingApp(); //创建BrowerAPP
// break;
// }
//
// // USER END
// break;
// case WM_NOTIFICATION_MOVED_OUT:
// // USER START (Optionally insert code for reacting on notification message)
// // USER END
// break;
// case WM_NOTIFICATION_SCROLL_CHANGED:
// // USER START (Optionally insert code for reacting on notification message)
// // USER END
// break;
// case WM_NOTIFICATION_SEL_CHANGED:
// // USER START (Optionally insert code for reacting on notification message)
// // USER END
// break;
// // USER START (Optionally insert additional code for further notification handling)
// // USER END
// }
// break;
// // USER START (Optionally insert additional code for further Ids)
// // USER END
// }
// break;
// // USER START (Optionally insert additional message handling)
// // USER END
// default:
// WM_DefaultProc(pMsg);
// break;
// }
//}
///*********************************************************************
//*
//* Public code
//*
//**********************************************************************
//*/
///*********************************************************************
//*
//* CreateWindow
//*/
//WM_HWIN CreateIconWindow(void) {
// WM_HWIN hWin;
// hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
// return hWin;
//}
//// USER START (Optionally insert additional public code)
//void icontest(void)
//{
// GUI_Init();
// WM_SetCreateFlags(WM_CF_MEMDEV);
// CreateIconWindow();
// while(1)
// {
// GUI_Delay(100);
//
// }
//
//}
//// USER END
///*************************** End of file ****************************/
另一个界面切换回去
#include "stepcount.h"
/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.40 *
* Compiled Jun 22 2017, 10:13:26 *
* (c) 2017 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
// USER START (Optionally insert additional includes)
// USER END
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_GRAPH_0 (GUI_ID_USER + 0x01)
#define ID_TEXT_0 (GUI_ID_USER + 0x02)
#define ID_TEXT_1 (GUI_ID_USER + 0x03)
#define ID_BUTTON_0 (GUI_ID_USER+0x04)
// USER START (Optionally insert additional defines)
#define RECOMMENDED_MEMORY (1024L * 20)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
static GRAPH_SCALE_Handle hScaleV;
static GRAPH_SCALE_Handle hScaleH;
static GRAPH_DATA_Handle ahData;
static uint32_t memnum;
static WM_HWIN hWin;
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 240, 0, 0x0, 0 },
{ GRAPH_CreateIndirect, "Graph", ID_GRAPH_0, 15, 15, 210, 160, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_0, 20, 180, 200, 25, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_1, 20, 205, 80, 20, 0, 0x64, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 165, 210, 70, 25, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbGraphDialog(WM_MESSAGE * pMsg) {
static WM_HWIN hItem;
// USER START (Optionally insert additional variables)
static int NCode;
static int Id;
// USER END
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
break;
case WM_INIT_DIALOG:
//
// Initialization of 'Graph'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_GRAPH_0);
ahData = GRAPH_DATA_YT_Create(GUI_GREEN,400,0,0);
GRAPH_AttachData(hItem,ahData);
GRAPH_SetGridDistY(hItem,20);
GRAPH_SetGridDistX(hItem,10);
GRAPH_SetGridVis(hItem,1);
hScaleV=GRAPH_SCALE_Create(13,GUI_TA_RIGHT,GRAPH_SCALE_CF_VERTICAL,25);
GRAPH_AttachScale(hItem,hScaleV);
hScaleH=GRAPH_SCALE_Create(150,GUI_TA_RIGHT,GRAPH_SCALE_CF_HORIZONTAL,25);
GRAPH_AttachScale(hItem,hScaleH);
GRAPH_SCALE_SetFactor(hScaleV,0.4);
GRAPH_SCALE_SetTextColor(hScaleV,GUI_RED);
GRAPH_SCALE_SetFactor(hScaleH,0.04);
GRAPH_SCALE_SetTextColor(hScaleH,GUI_RED);
GRAPH_SetBorder(hItem, 14, 0, 0, 13);
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
TEXT_SetFont(hItem, GUI_FONT_20_1);
TEXT_SetText(hItem, "Stepcount:");
//
// Initialization of 'Text'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
TEXT_SetFont(hItem, GUI_FONT_20_ASCII);
TEXT_SetText(hItem, "Calorie:");
// USER START (Optionally insert additional code for further widget initialization)
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_20_ASCII);
BUTTON_SetText(hItem, "Cancle");
// USER END
break;
// USER START (Optionally insert additional message handling)
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// hItem = pMsg->hWin;
if(WM_IsWindow(pMsg->hWin))
{
// WM_DeleteWindow(pMsg->hWin);
// hItem=0;
GUI_EndDialog(pMsg->hWin,0);
WM_DeleteWindow(pMsg->hWin);
icontest();
}
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
case WM_DELETE:
break;
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
static WM_HWIN CreateGraphWindow(void) {
static WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbGraphDialog, WM_HBKWIN, 0, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
void MainGraphTask(void)
{
if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
GUI_ErrorOut("Not enough memory available.");
return;
}
hWin=CreateGraphWindow();
while(1)
{
memnum=GUI_ALLOC_GetNumFreeBytes();
GRAPH_DATA_YT_AddValue(ahData,memnum/192);
GUI_Delay(100);
}
}
|
|