请问定义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);
}