static void _cbDialog(WM_MESSAGE * pMsg)
{
WM_HWIN hItem;
int NCode;
int Id;
WM_MESSAGE Msg;
switch (pMsg->MsgId)
{
case WM_INIT_DIALOG:
//初始化FRAMEWIN
hItem = pMsg->hWin;
FRAMEWIN_SetText(hItem, "EDIT USER");
FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
FRAMEWIN_SetFont(hItem, GUI_FONT_16B_ASCII);
//初始化EDIT 显示hello word
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0);
EDIT_EnableBlink(hItem, 500, 1);
EDIT_SetText(hItem, "Hello Word!");
EDIT_SetFont(hItem, &GUI_Font20_ASCII);
EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v; //得到数据值 也就是动作类型
switch(Id)
{
case GUI_ID_EDIT0: //EDIT控件通知消息
switch(NCode) //判断动作类型
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_VALUE_CHANGED:
break;
}
break;
case GUI_ID_OK:
switch(NCode) 判断动作类型
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
Msg.MsgId=WM_APP_SHOW_TEXT;
Msg.hWinSrc=pMsg->hWin;
WM_SendMessage(WM_HBKWIN,&Msg);
break;
}
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
初始化标题栏 :包括标题文本内容,字体大小,对齐方式##
case WM_INIT_DIALOG:
//初始化FRAMEWIN
hItem = pMsg->hWin;
FRAMEWIN_SetText(hItem, "EDIT USER");//内容
FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);//对齐方式
FRAMEWIN_SetFont(hItem, GUI_FONT_16B_ASCII);
//初始化EDIT 设置字体
初始化里面的提示内容
下面这个 函数很重要
WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0);
得到某个控件的窗口值
代码如下
//初始化EDIT
hItem = WM_GetDialogItem(pMsg->hWin, GUI_ID_EDIT0); //GUI_ID_EDITO在程序上面的资源表中找的到
EDIT_EnableBlink(hItem, 500, 1); //启用光标
EDIT_SetText(hItem, "Hello Word!"); //文本内容
EDIT_SetFont(hItem, &GUI_Font20_ASCII);//文本大小
EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);//对齐方式
对话框中有控件(例如:按钮)发生了动作
NCode = pMsg->Data.v pMsg->Data.v的值如下
代码如下
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);//得到控件ID号判断是哪个按钮或者哪个小控件发生了动作
NCode = pMsg->Data.v; //
switch(Id)
{
case GUI_ID_EDIT0: //EDIT控件通知消息
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
case WM_NOTIFICATION_VALUE_CHANGED:
break;
}
break;
case GUI_ID_OK: //**OK按钮发生了动作**
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
/*******************************************************************
如下代码很有用,经常用
*******************************************************************/
>
> **## WM_NOTIFICATION_RELEASED 此通知消息将在被点击的小工具已被释放时发送。 ##** 意思就是当按钮按下再释放时发送如下代码消息
>
> case WM_NOTIFICATION_RELEASED:
> Msg.MsgId=WM_APP_SHOW_TEXT;
> Msg.hWinSrc=pMsg->hWin;
> WM_SendMessage(WM_HBKWIN,&Msg);
> break;
}
}
break;
// #define WM_APP_SHOW_TEXT (WM_USER +0)
//M_USER 应用程序可使用 WM_USER 常数来定义私人消息,通常形式为
//WM_USER+X,其中 X 为整数值。
//背景窗口的回调函数
static void _BkCallback(WM_MESSAGE *pMsg)
{
static WM_HWIN hWin;
static WM_HWIN hEdit;
static U8 text;
char buffer[TEXT_MAXLEN];
switch(pMsg->MsgId)
{
case WM_PAINT:
GUI_SetBkColor(GUI_DARKGRAY);
GUI_Clear();
GUI_SetFont(&GUI_Font24_ASCII);
GUI_DispStringHCenterAt("WIDGET_Edit - Sample", 160, 5);
GUI_SetFont(&GUI_Font8x16);
if (text)
{
hEdit=WM_GetDialogItem(DialoghWin,GUI_ID_EDIT0);
GUI_DispStringHCenterAt("The string you have modified is:", 160, 90);
EDIT_GetText(hEdit, buffer, TEXT_MAXLEN);
GUI_DispStringHCenterAt(buffer, 160, 110);
}
else
{
GUI_DispStringHCenterAt("Use keyboard to modify string...", 160, 90);
}
break;
case WM_APP_SHOW_TEXT:
hWin=pMsg->hWinSrc;
WM_HideWindow(hWin); //隐藏对话框
text=1;
WM_InvalidateWindow(WM_HBKWIN); //背景窗口无效
WM_CreateTimer(WM_HBKWIN,0,3000,0); //定时处理
break;
case WM_TIMER: //时间到了接收到了定时的消息做出相应的处理
text=0;
WM_InvalidateWindow(WM_HBKWIN);
WM_ShowWindow(hWin);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
这正是我们之前所发送的自定义消息
WM_HideWindow(hWin); //隐藏对话框
WM_ShowWindow(hWin);