StemWin页面句柄管理,使用stack管理

在使用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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值