大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
刚开始接触emWin,记录一下我自己感悟的心得。
首先从GUIBuilder小工具创建的窗口文件讲解。
// USER START (Optionally insert additional static data)
#define BUTTON_SIZE_X 20
#define BUTTON_SIZE_Y 20
#define BUTTON_START_X 55
#define BUTTON_START_Y 90
#define BUTTON_GAP_XY 5
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 40, 125, 260,105, 0, 0x64, 0 },//相对于父窗口的Client区的位置
{ BUTTON_CreateIndirect, "q", ID_BUTTON_0, 5, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },//注意!控件位置是相对于窗口的
{ BUTTON_CreateIndirect, "w", ID_BUTTON_1, 30, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "e", ID_BUTTON_2, 55, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "r", ID_BUTTON_3, 80, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "t", ID_BUTTON_4, 105, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "y", ID_BUTTON_5, 130, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "u", ID_BUTTON_6, 155, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "i", ID_BUTTON_7, 180, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "o", ID_BUTTON_8, 205, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "p", ID_BUTTON_9, 230, 5, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "a", ID_BUTTON_10,5, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "s", ID_BUTTON_11,30, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "d", ID_BUTTON_12,55, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "f", ID_BUTTON_13,80, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "g", ID_BUTTON_14,105, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "h", ID_BUTTON_15,130, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "j", ID_BUTTON_16,155, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "k", ID_BUTTON_17, 180, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "l", ID_BUTTON_18, 205, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "_", ID_BUTTON_19, 230, 30, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "z", ID_BUTTON_20, 5, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "x", ID_BUTTON_21, 30, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "c", ID_BUTTON_22, 55, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "v", ID_BUTTON_23, 80, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "b", ID_BUTTON_24, 105, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "n", ID_BUTTON_25, 130, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "m", ID_BUTTON_26, 155, 55, BUTTON_SIZE_X, BUTTON_SIZE_Y, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Enter", ID_BUTTON_27, 200, 55, 50, 45, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "ESC", ID_BUTTON_28, 5, 80, 40, 20, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Caps", ID_BUTTON_29, 50, 80, 55, 20, 0x0, 0 },
{ BUTTON_CreateIndirect, "EN", ID_BUTTON_30, 110, 80, 30, 20, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Backsp", ID_BUTTON_31, 145, 80, 50, 20, 0, 0x0, 0 },
};
// USER START (Optionally insert additional widgets)
// USER END
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
static const char keyCAP[] = {
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', '_',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', 0};
static const char keyLOW[] = {
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '_',
'z', 'x', 'c', 'v', 'b', 'n', 'm', 0};
static const char key123[] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'!', '@', '%', '*', '(', ')', '_', '-', '+', '=',
'/', ':', ';', '"', ',', '.', '?', 0};
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem; //目标窗口
int NCode;
int Id,uib_num;
// USER START (Optionally insert additional variables)
char charBUFF[20];
static unsigned char capsKEY = 0, inputTYPE = 0;
WM_MESSAGE Message;
// USER END
switch (pMsg->MsgId) { //消息类型 MsgId 窗口发送的消息,窗口发生变化(内容,数值)时会发送
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
WINDOW_SetBkColor(hItem, (0x00C0C0C0));
for(uib_num=ID_BUTTON_0;uib_num <= ID_BUTTON_31;uib_num++)
{
hItem = WM_GetDialogItem(pMsg->hWin, uib_num);
BUTTON_SetFont(hItem, GUI_FONT_16_1);
BUTTON_SetFocussable(hItem, 0);
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc); //源窗口 hWinSrc 窗口中发送消息的控件(控件也是一个小窗口)
NCode = pMsg->Data.v; //数据值 Data.v (控件发送的消息,比如控件被点击,内容改变)
switch(Id) {
case ID_BUTTON_0:
case ID_BUTTON_1:
case ID_BUTTON_2:
case ID_BUTTON_3:
case ID_BUTTON_4:
case ID_BUTTON_5:
case ID_BUTTON_6:
case ID_BUTTON_7:
case ID_BUTTON_8:
case ID_BUTTON_9:
case ID_BUTTON_10:
case ID_BUTTON_11:
case ID_BUTTON_12:
case ID_BUTTON_13:
case ID_BUTTON_14:
case ID_BUTTON_15:
case ID_BUTTON_16:
case ID_BUTTON_17:
case ID_BUTTON_18:
case ID_BUTTON_19:
case ID_BUTTON_20:
case ID_BUTTON_21:
case ID_BUTTON_22:
case ID_BUTTON_23:
case ID_BUTTON_24:
case ID_BUTTON_25:
case ID_BUTTON_26:
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
BUTTON_GetText(pMsg->hWinSrc, &charBUFF[0], sizeof(charBUFF));
GUI_StoreKeyMsg(charBUFF[0], 1); //store key to EMWIN
GUI_StoreKeyMsg(charBUFF[0], 0);
// USER END
break;
}
break;
case ID_BUTTON_27: // Notifications sent by 'Enter'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
GUI_StoreKeyMsg(GUI_KEY_ENTER, 1);
GUI_StoreKeyMsg(GUI_KEY_ENTER, 0);
// 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)
case ID_BUTTON_28: // Notifications sent by 'ESC'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
WM_HideWindow(pMsg->hWin);
inputTYPE = (inputTYPE <= 0) ? 1 : (inputTYPE-1);
Message.hWinSrc = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_30);
Message.MsgId = WM_NOTIFY_PARENT;
Message.Data.v = WM_NOTIFICATION_RELEASED;
WM_SendMessage(pMsg->hWin, &Message);
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_29: // Notifications sent by 'Caps'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
capsKEY = !capsKEY;
if(inputTYPE==1) break;
if(capsKEY) BUTTON_SetTextColor(pMsg->hWinSrc, BUTTON_CI_UNPRESSED, GUI_RED);
else BUTTON_SetTextColor(pMsg->hWinSrc, BUTTON_CI_UNPRESSED, GUI_BLACK);
for(Id=ID_BUTTON_0; Id<=ID_BUTTON_26; Id++) //change to English keyboard
{
charBUFF[0] = capsKEY ? keyCAP[Id-ID_BUTTON_0] : keyLOW[Id-ID_BUTTON_0]; charBUFF[1] = 0;
BUTTON_SetText(WM_GetDialogItem(pMsg->hWin, Id), &charBUFF[0]);
BUTTON_SetTextColor(WM_GetDialogItem(pMsg->hWin, Id), BUTTON_CI_UNPRESSED, (!capsKEY&&(inputTYPE==2)) ? GUI_BLUE : GUI_BLACK);
}
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_30: // Notifications sent by 'En'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
inputTYPE = !inputTYPE;
if(!capsKEY){
if(inputTYPE)
for(uib_num=ID_BUTTON_0; uib_num<=ID_BUTTON_26; uib_num++)
{
BUTTON_SetTextColor(WM_GetDialogItem(pMsg->hWin, uib_num), BUTTON_CI_UNPRESSED, GUI_BLACK);
BUTTON_SetText(pMsg->hWinSrc, "123");
charBUFF[0] = key123[uib_num-ID_BUTTON_0]; charBUFF[1] = 0;
BUTTON_SetText(WM_GetDialogItem(pMsg->hWin, uib_num), &charBUFF[0]);
}
else
for(uib_num=ID_BUTTON_0; uib_num<=ID_BUTTON_26; uib_num++)
{
BUTTON_SetTextColor(WM_GetDialogItem(pMsg->hWin, uib_num), BUTTON_CI_UNPRESSED, GUI_BLACK);
BUTTON_SetText(pMsg->hWinSrc, "EN");
charBUFF[0] = keyLOW[uib_num-ID_BUTTON_0]; charBUFF[1] = 0;
BUTTON_SetText(WM_GetDialogItem(pMsg->hWin, uib_num), &charBUFF[0]);
}
}
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_31: // Notifications sent by 'Backspace'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
GUI_StoreKeyMsg(GUI_KEY_BACKSPACE, 1);
GUI_StoreKeyMsg(GUI_KEY_BACKSPACE, 0);
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateInput
*/
WM_HWIN CreateInput(void);
WM_HWIN CreateInput(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);//创建非阻塞对话框,父窗口的句柄为WM_HBKWIN
return hWin;
}
- 这实际上是我参照别人的按键程序,自己改写后的软键盘,所需要记录的都在代码中有注释,下面张贴一下效果图:
- 刚开始学习还有很多不会的,后续会继续记录自己的学习过程。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/223056.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...