STemWin学习:关于窗口消息的基础知识

STemWin学习:关于窗口消息的基础知识刚开始接触emWin,记录一下我自己感悟的心得。首先从GUIBuilder小工具创建的窗口文件讲解。//USERSTART(Optionallyinsertadditionalstaticdata)#defineBUTTON_SIZE_X20#defineBUTTON_SIZE_Y20#defineBUTTON_START_X55#define…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新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;
}

Jetbrains全家桶1年46,售后保障稳定

  1. 这实际上是我参照别人的按键程序,自己改写后的软键盘,所需要记录的都在代码中有注释,下面张贴一下效果图:STemWin学习:关于窗口消息的基础知识
  2. 刚开始学习还有很多不会的,后续会继续记录自己的学习过程。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/223056.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • mxgraph渲染页面_graph绘图

    mxgraph渲染页面_graph绘图Web绘图——mxGraph项目实战(精华篇)需求由于小论文实验需求,需要实现根据用户日志提取出行为序列,然后根据行为序列生成有向图的形式,并且连接相邻动作的弧上标有执行此次相邻动作的频次,每个动作另附有一个数据集,这样有向图加数据集就构成了用户交互图。为此,自己想到了mxGraph,遂决定学习之。起步此次项目实战是受阅读参考文献[1]启发,并在其图形布局实例基础上进行。其

    2022年10月25日
  • C# Modbus 通讯

    C# Modbus 通讯SpSetup类与Globalspace类publicpartialclassSpSetup:Form{#region定义变量///<summary>///发送报文///</summary>publicbyte[]sendData=ne…

  • java中Scanner类nextLine()和next()的区别和使用方法

    java中Scanner类nextLine()和next()的区别和使用方法在实现字符窗口的输入时,扫描器Scanner非常实用,操作起来也比较简单。在今天编程的过程中,我发现用Scanner实现字符串的输入有两种方法,一种是next(),一种nextLine(),但是这两种方法究竟有什么区别呢?我查了一些资料总结了一下,希望对大家有所帮助。           在实现字符窗口的输入时,扫描器Scanner非常实用,操作起来也比较简单。

  • 1.两数之和-Python-LeetCode

    1.两数之和-Python-LeetCode刚开始接触算法方面,好多都不懂,打算每刷一题就整理一下题目:给定一个整数数列,找出其中和为特定值的那两个数。你可以假设每个输入都只会有一种答案,同样的元素不能被重用。示例:给定nums=[2,7,11,15],target=9因为nums[0]+nums[1]=2+7=9所以返回[0,1]解法一:.刚开始看到的的时候,第一个想到的就是用一个嵌套循环把n…

  • android图片拖动缩放

    这篇图片拖拽缩放也是我在项目中用到的,今天整理一下,将源码奉献给大家,希望对大家以后碰到相似的问题有帮助。android大图片拖拽缩放这篇就不做过多介绍了,直接上源码:因为是大图片,在onDes

    2021年12月23日
  • 关于我对stm32看门狗的一些理解(基于正点原子)

    关于我对stm32看门狗的一些理解(基于正点原子)咕咕咕之后想更会儿stm32哈哈哈,但是其实是之前自己写的笔记,想着以后就写在一起吧,我自己也更好去找到自己写的玩意~毕竟总所周知,博客都是写给自己的。(虽然好像现在自己都看不懂了我的天哪)一.什么是看门狗在stm32中,我们会学到独立看门狗和窗口看门狗的实验。第一眼肯定是一脸懵逼啊,啥是看门狗啊?看门狗在日常生活中,大概的印象就是,起到一个保证安全,防止外来人员搞事的作用。stm32中的看门狗也起着差不多的意思:看门狗就是起到一个监督单片机是否正在正常运行的作用。如果程序运行异常(跑飞),那么

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号