论坛» 活动中心» 合作大赛

关于SUPPORT_BG的定义问题

菜鸟
2010-11-07 20:00 1楼

请问定义SUPPORT_BG有什么作用,比不定义SUPPORT_BG有什么功能不能实现吗?新建工程默认是定义SUPPORT_BG的,可为什么定义了SUPPORT_BG后,发送SMS消息或Start call后屏幕不能正常显示,而是出现“please delete layer”(如图)?


代码如下:
#include "vmsys.h"
#include "vmio.h"
#include "vmgraph.h"
#include "vmchset.h"
#include "vmstdlib.h"

/* ---------------------------------------------------------------------------
* global variables
* ------------------------------------------------------------------------ */

#define SUPPORT_BG


VMINT layer_hdl[1]; // layer handle array.

/* ---------------------------------------------------------------------------
* local variables
* ------------------------------------------------------------------------ */
/*
* system events
*/
void handle_sysevt(VMINT message, VMINT param);

/*
* key events
*/
void handle_keyevt(VMINT event, VMINT keycode);

/*
* pen events
*/
void handle_penevt(VMINT event, VMINT x, VMINT y);

/*
* demo
*/
static void draw_hello(void);

/**
* entry
*/
void vm_main(void)
{
layer_hdl[0] = -1;

vm_reg_sysevt_callback(handle_sysevt);
vm_reg_keyboard_callback(handle_keyevt);
vm_reg_pen_callback(handle_penevt);
}

void handle_sysevt(VMINT message, VMINT param)
{
#ifdef SUPPORT_BG
/* The application updates the screen when receiving the message VM_MSG_PAINT
* what is sent after the application is activated. The application can skip
* the process on screen when the VM_MSG_ACTIVE or VM_MSG_INACTIVE is received.
*/
switch (message)
{
case VM_MSG_CREATE:
/* the GDI operation is not recommended as the response of the message*/
break;
case VM_MSG_PAINT:
/* cerate base layer that has same size as the screen*/
/*If rotating screen is needed, and it rotates successful,
the application will receive the VM_MSG_PAINT event, then,
the application needs to delete the level and recreate it. */
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}

if( layer_hdl[0] == -1 )
{
layer_hdl[0] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);
}

/* set clip area */
vm_graphic_set_clip(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height());

draw_hello();
break;
case VM_MSG_SCREEN_ROTATE:
/*The application can rotate the screen*/
break;
case VM_MSG_HIDE:
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}
break;
case VM_MSG_QUIT:
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}
vm_exit_app();
break;
}
#else
switch (message)
{
case VM_MSG_CREATE:
case VM_MSG_ACTIVE:
/*cerate base layer that has same size as the screen*/
if( layer_hdl[0] == -1 )
{
layer_hdl[0] = vm_graphic_create_layer(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), -1);
}

/* set clip area*/
vm_graphic_set_clip(0, 0,
vm_graphic_get_screen_width(),
vm_graphic_get_screen_height());
break;

/*If rotating screen is needed, and it rotates successful,
the application will receive the VM_MSG_PAINT event, then,
the application needs to delete the level and recreate it. */
case VM_MSG_PAINT:
draw_hello();
break;
case VM_MSG_SCREEN_ROTATE:
/*The application can rotate the screen*/
break;
case VM_MSG_INACTIVE:
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}
break;
case VM_MSG_QUIT:
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}
vm_exit_app();
break;
}
#endif
}

void handle_keyevt(VMINT event, VMINT keycode)
{
/* press any key and return*/
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}

vm_exit_app();
}

void handle_penevt(VMINT event, VMINT x, VMINT y)
{
/* touch and return*/
if( layer_hdl[0] != -1 )
{
vm_graphic_delete_layer(layer_hdl[0]);
layer_hdl[0] = -1;
}

vm_exit_app();
}


static void draw_hello(void)
{
VMWCHAR s[50];
VMUINT8* buf;
int x, y, w;

vm_gb2312_to_ucs2(s, 50, "Hello, world!");
w = vm_graphic_get_string_width(s);
x = (vm_graphic_get_screen_width() - w) / 2;
y = (vm_graphic_get_screen_height() - vm_graphic_get_character_height()) / 2;

/* get the target buffer*/
buf = vm_graphic_get_layer_buffer(layer_hdl[0]);

/* fill the screen*/
vm_graphic_fill_rect(buf, 0, 0, vm_graphic_get_screen_width(),
vm_graphic_get_screen_height(), VM_COLOR_WHITE, VM_COLOR_BLACK);

/* draw text */
vm_graphic_textout(buf, x, y, s, wstrlen(s), VM_COLOR_BLUE);

/* flush the screen with data in the buffer*/
vm_graphic_flush_layer(layer_hdl, 1);
}

菜鸟
2010-11-08 09:24 2楼
SUPPORT_BG就是support background的缩写啊,也就是支持后台。

如果是不支持后台的程序,是vm_create,vm_active,vm_paint,vm_inactive,vm_exit这5个消息。否则就是vm_create,vm_paint,vm_hide,vm_exit这4个消息了。你也可以不定义SUPPORT_BG而直接在程序中选择上述两种消息机制。

大概就是这样吧。
共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]