在使用stemwin时,每个页面需要进行管理,新建一个就需要将其压入stack中,退出则销毁。
我在开发一个海上通讯设备时,使用此方式管理页面的句柄。
/**
* auther: zhang qiang
* brief: create a stack for store handleID(hWin),the function is usefull for menu when windows
* switch, enter next menu will store current menu to this stack, exit current menu will
* delete current window and pop previous window handleID from stack, show the window
* in LCD.
**/
#include "includes.h"
#include "db_drv.h"
#include "APP_Lib.h"
#include "WindowManageStack.h"
WindowManageStack_t WindowManage_Stack;
/**
* initiialize a stack for store handleID(hWin).the function is usefull for menu enter or exit.
**/
int WindowManage_StackInit(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
memset(WMS, 0, sizeof(WindowManageStack_t));
return 0;
}
/**
* clear current stack
**/
int WindowManage_StackClear(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
memset(WMS, 0, sizeof(WindowManageStack_t));
return 0;
}
/**
* push a window handleID to stack.
**/
int WindowManage_StackPush(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top >= WINDOW_MANAGE_STACK_LEN)
return -1;
memcpy(&WMS->data[WMS->top], node, sizeof(WindowNode_t));
WMS->top++;
return 0;
}
/**
* pop window page from stack.
**/
int WindowManage_StackPop(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top - 1 == -1)
return -1;
memcpy(node, &WMS->data[WMS->top - 1], sizeof(WindowNode_t));
WMS->top--;
return 0;
}
int WindowManage_StackCat(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top - 1 == -1)
return -1;
memcpy(node, &WMS->data[WMS->top - 1], sizeof(WindowNode_t));
return 0;
}
/**
* view all stack, you can find what you want to have.
**/
int WindowManage_StackPrintf(WindowManageStack_t *WMS)
{
int i;
if (WMS == NULL)
return -1;
for(i = 0; i <= WMS->top - 1; i++){
printf("top = %d hwind = %d, Item = %d\n", i, WMS->data[i].hWind, WMS->data[i].Item);
}
return 0;
}
/**
* check the stack empty?
**/
int WindowManage_StackEmpty(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
if (WMS->top - 1 < 0)
return 0;
return WMS->top;
}
在使用stemwin时,每个页面需要进行管理,新建一个就需要将其压入stack中,退出则销毁。
我在开发一个海上通讯设备时,使用此方式管理页面的句柄。
/**
* auther: zhang qiang
* brief: create a stack for store handleID(hWin),the function is usefull for menu when windows
* switch, enter next menu will store current menu to this stack, exit current menu will
* delete current window and pop previous window handleID from stack, show the window
* in LCD.
**/
#include "includes.h"
#include "db_drv.h"
#include "APP_Lib.h"
#include "WindowManageStack.h"
WindowManageStack_t WindowManage_Stack;
/**
* initiialize a stack for store handleID(hWin).the function is usefull for menu enter or exit.
**/
int WindowManage_StackInit(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
memset(WMS, 0, sizeof(WindowManageStack_t));
return 0;
}
/**
* clear current stack
**/
int WindowManage_StackClear(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
memset(WMS, 0, sizeof(WindowManageStack_t));
return 0;
}
/**
* push a window handleID to stack.
**/
int WindowManage_StackPush(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top >= WINDOW_MANAGE_STACK_LEN)
return -1;
memcpy(&WMS->data[WMS->top], node, sizeof(WindowNode_t));
WMS->top++;
return 0;
}
/**
* pop window page from stack.
**/
int WindowManage_StackPop(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top - 1 == -1)
return -1;
memcpy(node, &WMS->data[WMS->top - 1], sizeof(WindowNode_t));
WMS->top--;
return 0;
}
int WindowManage_StackCat(WindowManageStack_t *WMS, WindowNode_t *node)
{
if (WMS == NULL || node == NULL)
return -1;
if (WMS->top - 1 == -1)
return -1;
memcpy(node, &WMS->data[WMS->top - 1], sizeof(WindowNode_t));
return 0;
}
/**
* view all stack, you can find what you want to have.
**/
int WindowManage_StackPrintf(WindowManageStack_t *WMS)
{
int i;
if (WMS == NULL)
return -1;
for(i = 0; i <= WMS->top - 1; i++){
printf("top = %d hwind = %d, Item = %d\n", i, WMS->data[i].hWind, WMS->data[i].Item);
}
return 0;
}
/**
* check the stack empty?
**/
int WindowManage_StackEmpty(WindowManageStack_t *WMS)
{
if (WMS == NULL)
return -1;
if (WMS->top - 1 < 0)
return 0;
return WMS->top;
}