|
发表于 2021-1-12 09:15:29
|
显示全部楼层
//数字小键盘,构建的源代码,绝对是自己原创,都使用好多年了!
/* Array of keys */
static int _aKey[] = {
GUI_KEY_ESCAPE,
GUI_KEY_BACKSPACE,
GUI_KEY_DELETE,
GUI_KEY_INSERT,
GUI_KEY_ENTER,
GUI_KEY_LEFT,
GUI_KEY_RIGHT
};
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__, ________
};
/* Dialog resource of numpad */
static const GUI_WIDGET_CREATE_INFO _aDialogNumPad[] = {
/* Function Text Id Px Py Dx Dy */
{ WINDOW_CreateIndirect, 0, 0, 40, 110, 176, 136+30},
{ EDIT_CreateIndirect, "", GUI_ID_EDIT1, 5, 5, 176, 30},
{ BUTTON_CreateIndirect, "Del", GUI_ID_USER + 15, 5, 5+30, 30, 30},
{ BUTTON_CreateIndirect, "7", GUI_ID_USER + 7, 37, 5+30, 30, 30},
{ BUTTON_CreateIndirect, "8", GUI_ID_USER + 8, 69, 5+30, 30, 30},
{ BUTTON_CreateIndirect, "9", GUI_ID_USER + 9, 101, 5+30, 30, 30},
{ BUTTON_CreateIndirect, "Bcks", GUI_ID_USER + 14, 133, 5+30, 36, 30},
{ BUTTON_CreateIndirect, ":", GUI_ID_USER + 13, 5, 37+30, 30, 30},
{ BUTTON_CreateIndirect, "4", GUI_ID_USER + 4, 37, 37+30, 30, 30},
{ BUTTON_CreateIndirect, "5", GUI_ID_USER + 5, 69, 37+30, 30, 30},
{ BUTTON_CreateIndirect, "6", GUI_ID_USER + 6, 101, 37+30, 30, 30},
{ BUTTON_CreateIndirect, "Ins", GUI_ID_USER + 16, 133, 37+30, 36, 30},
{ BUTTON_CreateIndirect, "+", GUI_ID_USER + 12, 5, 69+30, 30, 30},
{ BUTTON_CreateIndirect, "1", GUI_ID_USER + 1, 37, 69+30, 30, 30},
{ BUTTON_CreateIndirect, "2", GUI_ID_USER + 2, 69, 69+30, 30, 30},
{ BUTTON_CreateIndirect, "3", GUI_ID_USER + 3, 101, 69+30, 30, 30},
{ BUTTON_CreateIndirect, "Ent", GUI_ID_USER + 17, 133, 69+30, 36, 30},
{ BUTTON_CreateIndirect, 0, GUI_ID_USER + 18, 5, 101+30, 30, 30}, //ArrowLeft
{ BUTTON_CreateIndirect, "0", GUI_ID_USER + 0, 37, 101+30, 30, 30},
{ BUTTON_CreateIndirect, "-", GUI_ID_USER + 11, 69, 101+30, 30, 30},
{ BUTTON_CreateIndirect, ".", GUI_ID_USER + 10, 101, 101+30, 30, 30},
{ BUTTON_CreateIndirect, 0, GUI_ID_USER + 19, 133, 101+30, 36, 30}, //ArrowRight
};
/*
********************************************************************
*
* _cbDialogNumPad
*
********************************************************************
*/
static void _cbDialogNumPad(WM_MESSAGE * pMsg) {
GUI_RECT r;
int i, NCode, Id, Pressed = 0;
WM_HWIN hDlg, hItem;
WM_MESSAGE end_Msg;
hDlg = pMsg->hWin;
switch (pMsg->MsgId) {
case KEYPAD_UPDATE_MSG: //数字小键盘: 更新数据消息
if(kpad_mdf.id_press>0){
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT1);
EDIT_SetText(hItem,kpad_mdf.mdf_buff);
}else{
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT1);
EDIT_SetText(hItem,"");
}
WM_SetFocus(hItem);
break;
case WM_PAINT:
WM_GetClientRect(&r);
GUI_SetColor(0x000000);
GUI_DrawRect(r.x0, r.y0, r.x1, r.y1); /* Draw rectangle around it */
/* Draw the bright sides */
GUI_SetColor(0xffffff);
GUI_DrawHLine(r.y0 + 1, r.x0 + 1, r.x1 - 2); /* Draw top line */
GUI_DrawVLine(r.x0 + 1, r.y0 + 1, r.y1 - 2);
/* Draw the dark sides */
GUI_SetColor(0x555555);
GUI_DrawHLine(r.y1-1, r.x0 + 1, r.x1 - 1);
GUI_DrawVLine(r.x1-1, r.y0 + 1, r.y1 - 2);
break;
case WM_INIT_DIALOG:
for (i = 0; i < GUI_COUNTOF(_aDialogNumPad) - 1; i++) {
hItem = WM_GetDialogItem(hDlg, GUI_ID_USER + i);
BUTTON_SetFont(hItem, &GUI_FontHZ_Saf_16);
BUTTON_SetFocussable(hItem, 0); /* Set all buttons non focussable */
switch (i) {
case 18:
BUTTON_SetBitmapEx(hItem, 0, &_bmArrowLeft, 10, 12); /* Set bitmap for arrow left button (unpressed) */
BUTTON_SetBitmapEx(hItem, 1, &_bmArrowLeft, 10, 12); /* Set bitmap for arrow left button (pressed) */
break;
case 19:
BUTTON_SetBitmapEx(hItem, 0, &_bmArrowRight, 10, 12); /* Set bitmap for arrow right button (unpressed) */
BUTTON_SetBitmapEx(hItem, 1, &_bmArrowRight, 10, 12); /* Set bitmap for arrow right button (pressed) */
break;
}
}
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT1);
EDIT_SetMaxLen(hItem,30);
EDIT_SetBkColor(hItem,0,GUI_BLACK);
EDIT_SetFont(hItem,&GUI_Font24B_1);
EDIT_SetTextAlign(hItem,GUI_TA_VCENTER|GUI_TA_LEFT);
EDIT_SetTextColor(hItem,0,GUI_RED);
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */
NCode = pMsg->Data.v; /* Notification code */
switch (NCode) {
case WM_NOTIFICATION_CLICKED:
if(Id ==(GUI_ID_USER + 17)) { //"ENT"按键----按下
hItem =WM_GetDialogItem(hDlg, GUI_ID_USER + 17);
BUTTON_SetBkColor(hItem,BUTTON_CI_PRESSED,GUI_GREEN); //按下时--绿色背景
}
Pressed = 1;
break;
case WM_NOTIFICATION_RELEASED:
if ((Id >= GUI_ID_USER) && (Id <= (GUI_ID_USER + GUI_COUNTOF(_aDialogNumPad) - 1))) {
int Key;
if (Id < GUI_ID_USER + 14) {
char acBuffer[10];
BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); /* Get the text of the button */
Key = acBuffer[0];
} else {
Key = _aKey[Id - GUI_ID_USER - 13]; /* Get the text from the array */
if(Id ==(GUI_ID_USER + 17)){ //"ENT"按键---抬起
hItem =WM_GetDialogItem(hDlg, GUI_ID_USER + 17);
BUTTON_SetBkColor(hItem,BUTTON_CI_UNPRESSED,0xAAAAAA);
hItem = WM_GetDialogItem(hDlg, GUI_ID_EDIT1);
EDIT_GetText(hItem,kpad_mdf.mdf_buff,sizeof(kpad_mdf.mdf_buff));
kpad_mdf.flag_ent=1;//set
end_Msg.MsgId = KEYPAD_UPDATE_END; //向源窗体--->发送确认修改消息
WM_SendMessage(WM_GetClientWindow(kpad_mdf.wm_src), &end_Msg);
}
}
Pressed = 1;
GUI_SendKeyMsg(Key, Pressed); /* Send a key message to the focussed window */
}
break;
}
default:
WM_DefaultProc(pMsg);
}
}
/***最右上角,关闭数字小键盘按钮的回调函数*****/
static void _cbPadClose(WM_MESSAGE *pMsg)
{
if (pMsg->MsgId == WM_NOTIFY_PARENT_REFLECTION){
WM_HideWindow(pMsg->hWinSrc); // 隐藏窗体
WM_HideWindow(hNumPad); // 隐藏小键盘
return;
}
BUTTON_Callback(pMsg);
}
void Virtual_KeyPadWin(void)
{
hwin_keypad=FRAMEWIN_CreateEx(
40,90,176, 20,0,WM_CF_HIDE| WM_CF_STAYONTOP,
FRAMEWIN_CF_MOVEABLE, 0,"Keypad",_cbWinPad_key
);
hButton_pad=FRAMEWIN_AddButton(hwin_keypad,FRAMEWIN_BUTTON_RIGHT,0,GUI_ID_USER +101);
WM_SetCallback(hButton_pad, _cbPadClose); //添加增加按钮的回调函数
hNumPad = GUI_CreateDialogBox(_aDialogNumPad, GUI_COUNTOF(_aDialogNumPad),_cbDialogNumPad, WM_HBKWIN, 0, 0);
WM_SetStayOnTop(hwin_keypad, 1);
WM_SetStayOnTop(hNumPad, 1);
WM_HideWindow(hNumPad); //隐藏
while(1) {
OSTimeDly (100);
}
}
|
|