static voidcbBackgroundWin(WM_MESSAGE* pMsg) 
{
switch(pMsg->MsgId) 
{
caseWM_PAINT:    GUI_Clear();
default:         WM_DefaultProc(pMsg);
}
}

/* 前景窗的回调函数 */

static voidcbForegroundWin(WM_MESSAGE* pMsg) 
{
switch(pMsg->MsgId) 
{
caseWM_PAINT:    GUI_SetBkColor(GUI_GREEN);
GUI_Clear();
GUI_DispString("Foregroundwindow");
default:         WM_DefaultProc(pMsg);
}
}
/*  回调机制 */
static voidDemoRedraw(void) 
{
GUI_HWIN hWnd;
while(1) 
{
/*创建一个前景窗 */
hWnd =WM_CreateWindow(10, 10, 100, 100, WM_CF_SHOW, cbForegroundWin, 0);
/*显示前景窗*/
GUI_Delay(1000);
/* 删除前景窗 */
WM_DeleteWindow(hWnd);
GUI_DispStringAt("Backgroundof window has not been redrawn", 10, 10);
/* 等待,显示并不重绘 */
GUI_Delay(1000);
GUI_Clear();
/* 配置背景窗的回调功能 */
WM_SetCallback(WM_HBKWIN,cbBackgroundWin);
/*创建一个前景窗 */
hWnd =WM_CreateWindow(10, 10, 100, 100,WM_CF_SHOW, cbForegroundWin, 0);
/* 显示前景窗*/
GUI_Delay(1000);
/*删除前景窗 */
WM_DeleteWindow(hWnd);
/* 等待,显示将重绘*/
GUI_Delay(1000);
/* 删除回调函数 */
WM_SetCallback(WM_HBKWIN,0);
}
}
voidmain(void) 
{
GUI_Init();
DemoRedraw();
}
static voidcbBackgroundWin(WM_MESSAGE* pMsg) 
{
switch(pMsg->MsgId) 
{
caseWM_PAINT:    GUI_Clear();
default:         WM_DefaultProc(pMsg);
}
}

/* 前景窗的回调函数 */

static voidcbForegroundWin(WM_MESSAGE* pMsg) 
{
switch(pMsg->MsgId) 
{
caseWM_PAINT:    GUI_SetBkColor(GUI_GREEN);
GUI_Clear();
GUI_DispString("Foregroundwindow");
default:         WM_DefaultProc(pMsg);
}
}
/*  回调机制 */
static voidDemoRedraw(void) 
{
GUI_HWIN hWnd;
while(1) 
{
/*创建一个前景窗 */
hWnd =WM_CreateWindow(10, 10, 100, 100, WM_CF_SHOW, cbForegroundWin, 0);
/*显示前景窗*/
GUI_Delay(1000);
/* 删除前景窗 */
WM_DeleteWindow(hWnd);
GUI_DispStringAt("Backgroundof window has not been redrawn", 10, 10);
/* 等待,显示并不重绘 */
GUI_Delay(1000);
GUI_Clear();
/* 配置背景窗的回调功能 */
WM_SetCallback(WM_HBKWIN,cbBackgroundWin);
/*创建一个前景窗 */
hWnd =WM_CreateWindow(10, 10, 100, 100,WM_CF_SHOW, cbForegroundWin, 0);
/* 显示前景窗*/
GUI_Delay(1000);
/*删除前景窗 */
WM_DeleteWindow(hWnd);
/* 等待,显示将重绘*/
GUI_Delay(1000);
/* 删除回调函数 */
WM_SetCallback(WM_HBKWIN,0);
}
}
voidmain(void) 
{
GUI_Init();
DemoRedraw();
}

程式清单4.2中,回调函数执行的功能依赖于所接收到的消息。Switch语句中根据消息的类型,分别执行不同的功能。

WM_MESSAGE的成员如下:

MsgId:消息类型

HWin:目的窗口

HWinSrc: 源窗口

Data.p : 数据指针

Data.v: 数据值

其中MsgId的类型如下:

WM_PAINT: 窗口重绘

WM_CREATE: 窗口一建立就发送

WM_DELETE: 窗口一删除就发送

WM_SIZE :窗口尺寸发生改变就发送

WM_MOVE :窗口移动就发送

WM_SHOW :接收到show命令就发送

WM_HIDE :接收到hide命令就发送

WM_TOUCH:触摸屏信息

应用程式还能够为自己定义额外的消息。为确保他们不用到uC/GUI的消息ID,用户定义的消息从WM_USER后面开始,如:

#defineMY_MESSAGE_AAA WM_USER +0

#defineMY_MESSAGE_BBB WM_USER +

发表回复