我在界面中使用了,两个edit,当点击edit的时候,清空里面的显示,问题是WM_NOTIFY_CHILD_HAS_FOCUS在交替点击的时候,会每个都响应一次,导致交替的时候,把之前点击的内容也清空,这个在下面三个内容中,得到解答
static void _OnTouch(EDIT_Handle hObj, EDIT_Obj* pObj, WM_MESSAGE*pMsg) {
GUI_TOUCH_tState* pState = (GUI_TOUCH_tState*)pMsg->Data.p;
if (pMsg->Data.p) { /* Something happened in our area (pressed or released) */
if (pState->Pressed) {
GUI_DEBUG_LOG1("EDIT__Callback(WM_TOUCH, Pressed, Handle %d)\n",1);
_SetCursor(hObj, pObj, pState->x);
WM_SetFocus(hObj);
} else {
GUI_DEBUG_LOG1("EDIT__Callback(WM_TOUCH, Released, Handle %d)\n",1);
}
} else {
GUI_DEBUG_LOG1("_EDIT_Callback(WM_TOUCH, Moved out, Handle %d)\n",1);
}
}
int WM_SetFocus(WM_HWIN hWin) {
int r;
WM_MESSAGE Msg;
WM_LOCK();
if ((hWin) && (hWin != WM__hWinFocus)) {
Msg.MsgId = WM_SET_FOCUS;
/* Send a "no more foucs" message to window losing focus */
Msg.Data.v = 0;
WM_SendMessage(WM__hWinFocus, &Msg);
/* Send "You have the focus now" message to the window */
Msg.Data.v = 1;
WM_SendMessage(WM__hWinFocus = hWin, &Msg);
r = Msg.Data.v;
} else {
r = 1;
}
WM_UNLOCK();
return r;
}
int WIDGET_HandleActive(WM_HWIN hObj, WM_MESSAGE* pMsg) {
WM_MESSAGE Msg;
WIDGET* pWidget = WIDGET_H2P(hObj);
switch (pMsg->MsgId) {
case WM_GET_ID:
pMsg->Data.v = pWidget->Id;
return 0; /* Message handled -> Return */
case WM_SET_FOCUS:
if (pMsg->Data.v == 1) {
WIDGET_SetState(hObj, pWidget->State | WIDGET_STATE_FOCUS); // ( 1 )
} else {
WIDGET_SetState(hObj, pWidget->State & ~WIDGET_STATE_FOCUS);
}
Msg.MsgId = WM_NOTIFY_CHILD_HAS_FOCUS; // ( 2 )
Msg.Data.v = pMsg->Data.v;
WM_SendToParent(hObj, &Msg);
return 0;
case WM_GET_HAS_FOCUS:
。。。。
}
将2,放到1的后面就可以了。