|
仿照emWin官方小键盘demo, 在edit编辑框单机后弹出数字小键盘后,光标不闪烁,但是聚焦貌似还在edit编辑框上。如何让edit的编辑框闪烁。
PS:在群友说了在创建窗口后再次聚焦edit以及 在创建键盘后禁止聚焦button控件。试了下都没有用。
附上源码:
/*********************************************************************
* *
* SEGGER Microcontroller GmbH & Co. KG *
* Solutions for real time microcontroller applications *
* *
**********************************************************************
* *
* C-file generated by: *
* *
* GUI_Builder for emWin version 5.32 *
* Compiled Oct 8 2015, 11:59:02 *
* (c) 2015 Segger Microcontroller GmbH & Co. KG *
* *
**********************************************************************
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
*/
// USER START (Optionally insert additional includes)
// USER END
#include "DIALOG.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_FRAMEWIN_0 (GUI_ID_USER + 15)
#define ID_EDIT_0 (GUI_ID_USER + 16)
#define ID_TEXT_0 (GUI_ID_USER + 17)
#define ID_BUTTON_0 (GUI_ID_USER + 18)
#define TEXT_MAXLEN 40
// USER START (Optionally insert additional defines)
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 800, 480, 0, 0x64, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_0, 191, 110, 107, 28, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "", ID_TEXT_0, 250, 241, 188, 37, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button", ID_BUTTON_0, 407, 105, 97, 34, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
static WM_HWIN hEdit = 0;
static U8 ShowText = 0;
char aBuffer[TEXT_MAXLEN];
WM_HWIN hWin = pMsg->hWin;
// USER START (Optionally insert additional variables)
// USER END
memset(aBuffer, 0, TEXT_MAXLEN);
//把edit文字缓冲区清空,防止未输入就按set后出现乱码。
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Framewin'
//
hItem = pMsg->hWin;
FRAMEWIN_SetText(hItem, "TEST");
FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
FRAMEWIN_SetFont(hItem, GUI_FONT_32_ASCII);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, GUI_FONT_16B_ASCII);
BUTTON_SetText(hItem, "Set");
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
EDIT_SetText(hItem, "");
WM_SetFocus(hItem);
EDIT_EnableBlink(hItem, 100, 1);
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
case WM_PAINT:
if (ShowText) {
GUI_SetFont(&GUI_Font16B_ASCII);
EDIT_GetText(hEdit, aBuffer, TEXT_MAXLEN);
TEXT_SetText(WM_GetDialogItem(hWin, ID_TEXT_0), aBuffer);
GUI_Clear();
ShowText = 0;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
WM_HWIN hnumpad;
switch (Id) {
case ID_EDIT_0: // Notifications sent by 'Edit'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
hEdit = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
WM_SetFocus(hEdit);
// USER START (Optionally insert code for reacting on notification message)
CreateNumpad();
WM_SetFocus(hEdit);
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_VALUE_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
/*
if (hEdit == 0) {
hEdit = pMsg->hWinSrc;
}
*/
//hEdit = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0); //获取edit控件的句柄
//在edit控件更改内容消息中不能使用获取API,EDIT_GetText。可以在此处赋值句柄,窗口重绘时赋值缓冲区。
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_0: // Notifications sent by 'Button'
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
ShowText = 1;
WM_DeleteWindow(hnumpad);
//GUI_EndDialog(hnumpad,0); 关闭对话框错误
//WM_HideWindow();
//WM_InvalidateWindow(pMsg->hWin);
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* CreateFramewin
*/
WM_HWIN CreateFramewin(void);
WM_HWIN CreateFramewin(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
/*********************************************************************
*
* 创建数字键盘左右方向键位图
*
**********************************************************************
*/
static GUI_CONST_STORAGE GUI_COLOR _aColorsArrow[] = {
0xFFFFFF, 0x000000
};
static GUI_CONST_STORAGE GUI_LOGPALETTE _PalArrow = {
2, /* number of entries */
1, /* No transparency */
&_aColorsArrow[0]
};
static GUI_CONST_STORAGE unsigned char _acArrowRight[] = {
____XX__, ________,
____XXXX, ________,
XXXXXXXX, XX______,
____XXXX, ________,
____XX__, ________
};
static GUI_CONST_STORAGE unsigned char _acArrowLeft[] = {
____XX__, ________,
__XXXX__, ________,
XXXXXXXX, XX______,
__XXXX__, ________,
____XX__, ________
};
static GUI_CONST_STORAGE GUI_BITMAP _bmArrowRight = {
10, /* XSize */
5, /* YSize */
2, /* BytesPerLine */
1, /* BitsPerPixel */
_acArrowRight, /* Pointer to picture data (indices) */
&_PalArrow /* Pointer to palette */
};
static GUI_CONST_STORAGE GUI_BITMAP _bmArrowLeft = {
10, /* XSize */
5, /* YSize */
2, /* BytesPerLine */
1, /* BitsPerPixel */
_acArrowLeft, /* Pointer to picture data (indices) */
&_PalArrow /* Pointer to palette */
};
//
// Array of keys
//
/******************************************************************
*
*功能按键消息定义
*
全局变量
*******************************************************************/
static int _aKey[] = { GUI_KEY_BACKSPACE, GUI_KEY_TAB, GUI_KEY_LEFT, GUI_KEY_RIGHT };
/*********************************************************************
*
* 数字键盘对话框创建
*
【注】1.左右方向键文字由位图绘制
**********************************************************************
*/
static const GUI_WIDGET_CREATE_INFO _aDialogNumPad[] = {
//
// Function Text Id Px Py Dx Dy
//
{ WINDOW_CreateIndirect, 0 , 0 , 0, 0, 168, 270, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "7", GUI_ID_USER + 7, 10, 10, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "8", GUI_ID_USER + 8, 60, 10, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "9", GUI_ID_USER + 9, 110, 10, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "4", GUI_ID_USER + 4, 10, 60, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "5", GUI_ID_USER + 5, 110, 60, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "6", GUI_ID_USER + 6, 60, 60, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "1", GUI_ID_USER + 1, 10, 110, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "2", GUI_ID_USER + 2, 60, 110, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "3", GUI_ID_USER + 3, 110, 110, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "0", GUI_ID_USER + 0, 10, 160, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, ".", GUI_ID_USER + 10, 60, 160, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Bak", GUI_ID_USER + 11, 110, 160, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Tab", GUI_ID_USER + 12, 10, 210, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, 0, GUI_ID_USER + 13, 60, 210, 45, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, 0, GUI_ID_USER + 14, 110, 210, 45, 45, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* 数字键盘对话框回调函数
*
**********************************************************************
*/
static void _cbDialogNumPad(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
WM_HWIN hDlg;
int NCode;
int Pressed; //按键状态
unsigned Id;
unsigned i;
Pressed = 0; //按键状态初值
hDlg = pMsg->hWin;//获取对话框中其他控件句柄
//消息通知
switch (pMsg->MsgId) {
//窗口重绘消息
case WM_PAINT:
//键盘背景为亮灰色
GUI_SetBkColor(GUI_LIGHTGRAY);
GUI_Clear();
break;
//窗口初始化消息
case WM_INIT_DIALOG:
//设置所有按钮控件禁止聚焦(重要!同时刻所有控件只有一个控件可以聚焦,不禁止按钮聚焦,按下按钮后,按钮自动聚焦,此时编辑框聚焦失效)
for (i = 0; i < GUI_COUNTOF(_aDialogNumPad)-1 ; i++) {
hItem = WM_GetDialogItem(hDlg, GUI_ID_USER + i);
BUTTON_SetFocussable(hItem, 0);
switch (i) {
case 13://左键按钮位图设置
BUTTON_SetBitmapEx(hItem, 0, &_bmArrowLeft, 20, 20); /* Set bitmap for arrow left button (unpressed) */
BUTTON_SetBitmapEx(hItem, 1, &_bmArrowLeft, 20, 20); /* Set bitmap for arrow left button (pressed) */
break;
case 14://右键按钮位图设置
BUTTON_SetBitmapEx(hItem, 0, &_bmArrowRight, 20, 20); /* Set bitmap for arrow right button (unpressed) */
BUTTON_SetBitmapEx(hItem, 1, &_bmArrowRight, 20, 20); /* Set bitmap for arrow right button (pressed) */
break;
}
}
//按钮控件句柄值返回,防止出错
WM_GetDialogItem(hDlg, GUI_ID_USER + 12);
break;
break;
//窗口子控件消息
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */ //控件id
NCode = pMsg->Data.v; /* Notification code */ //通知码
switch (NCode) {
//子控件被点击
case WM_NOTIFICATION_CLICKED:
Pressed = 1;
//【注】此位置没有break,点击后继续执行释放消息判断
//子控件被释放
case WM_NOTIFICATION_RELEASED:
//若触发消息的控件ID为定义的全部15个按键中的一个
if ((Id >= GUI_ID_USER) && (Id <= (GUI_ID_USER + GUI_COUNTOF(_aDialogNumPad) - 1))) {
int Key;
//触发消息的控件为数字按键以及'.''Bak'
if (Id < GUI_ID_USER + 11) {
char acBuffer[10];
BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); //获取按键文本,并存储acBuffer缓冲区中
Key = acBuffer[0];//存储键位值
}
else {
//触发消息的控件为‘Tab’以及方向键
Key = _aKey[Id - GUI_ID_USER - 11]; //获取此按键对应键盘消息,即全局变量_aKey中的四个值 /* Get the text from the array */
}
/*发送消息给当前聚焦的窗口,即创建键盘的编辑框控件*/
GUI_SendKeyMsg(Key, Pressed); /* Send a key message to the focussed window */
}
break;
}
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* CreateNumpad
*/
WM_HWIN CreateNumpad(void);
WM_HWIN CreateNumpad(void) {
WM_HWIN hnumpad;
WM_HWIN hEdit;
hnumpad = GUI_CreateDialogBox(_aDialogNumPad, GUI_COUNTOF(_aDialogNumPad), _cbDialogNumPad, WM_HBKWIN, 0, 0);
return hnumpad;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
void MainTask(void) {
GUI_Init();
CreateFramewin();
while (1)
{
GUI_Delay(10);
}
}
/*************************** End of file ****************************/
|
-
-
|