专家
公告
财富商城
电子网
旗下网站
首页
问题库
专栏
标签库
话题
专家
NEW
门户
发布
提问题
发文章
STemWin 窗口中的按键怎么与触摸屏坐标对应?
2019-03-23 17:25
发布
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
站内问答
/
STM32/STM8
4265
2
1024
STemWin窗口中的按键是怎么与触摸屏坐标对应?窗口中显示一个按钮,当触摸该按钮时,怎么知道该按钮按下?
此帖出自
小平头技术问答
友情提示:
此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
dageliu
2019-03-24 05:56
DavidZH 发表于 2017-11-8 18:13
有事件的
我在窗口上放了一个按钮,但触摸该按钮时一直没反应,直接显示触摸点数据是没问题的,是不是我哪里配置有问题呀?看别的例程里都没有添加WM_TOUCH事件消息。我的代码如下,
#include "DIALOG.h"
#include "stdio.h"
#include "math.h"
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_BUTTON_2 (GUI_ID_USER + 0x03)
#define ID_TEXT_1 (GUI_ID_USER + 0x04)
#define ID_TEXT_2 (GUI_ID_USER + 0x05)
extern GUI_CONST_STORAGE GUI_FONT GUI_FontsongFont16;
extern int abs(int);
// USER START (Optionally insert additional defines)
/*void GUI_intToString(int num,char *s)
{
int temp,i;
i = 0;
if(num == 0)
{
*s = '0';
}
else if(num<0)
{
temp=abs(num);
*s = '-';
s++;
i++;
}
while(num!=0)
{
temp=num%10;
switch (temp){
case 0:
*s = '0';
s++;
i++;
break;
case 1:
*s = '1';
s++;
i++;
break;
case 2:
*s = '2';
s++;
i++;
break;
case 3:
*s = '3';
s++;
i++;
break;
case 4:
*s = '4';
s++;
i++;
break;
case 5:
*s = '5';
s++;
i++;
break;
case 6:
*s = '6';
s++;
i++;
break;
case 7:
*s = '7';
s++;
i++;
break;
case 8:
*s = '8';
s++;
i++;
break;
case 9:
*s = '9';
s++;
i++;
break;
default :
break;
}
}
}*/
// USER END
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
// USER START (Optionally insert additional static data)
// USER END
/*********************************************************************
*
* _aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 400, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Start", ID_BUTTON_0, 70, 160, 100, 40, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Set1", ID_BUTTON_1, 70, 220, 100, 40, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Set2", ID_BUTTON_2, 70, 280, 100, 40, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "xinye", ID_TEXT_1, 80, 60, 100, 40, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Hello STemWin", ID_TEXT_2, 80, 80, 100, 40, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
void intToString(int num,char *buf)
{
int temp;
temp = num;
if(temp>=1000)
temp%=1000;
while(temp>0)
{
*buf++=temp%10;
temp/=10;
}
}
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
//GUI_PID_STATE TouchState;
static int flag = 0;
int NCode;
int Id;
//char touchBuf[3];
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_PAINT:
if(!flag){
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetFont(hItem, &GUI_Font16_ASCII);
TEXT_SetText(hItem,"Hello World!");
}
break;
case WM_INIT_DIALOG:
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
//
// Initialization of 'Button'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
// USER START (Optionally insert additional code for further widget initialization)
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
TEXT_SetFont(hItem, &GUI_Font16_ASCII);
// USER END
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button'
switch(NCode)
{
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
}
break;
case ID_BUTTON_1:
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
flag = !flag;
WM_InvalidateWindow(pMsg->hWin);
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetFont(hItem, &GUI_Font16_ASCII);
TEXT_SetText(hItem,"Hello World!");
break;
}
break;
case ID_BUTTON_2:
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
break;
case WM_NOTIFICATION_RELEASED:
break;
}
break;
}
break;
case WM_TOUCH:
break;
//hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
//TEXT_SetFont(hItem, &GUI_Font16_ASCII);
//GUI_TOUCH_GetState(&TouchState);
//TEXT_SetText(hItem,"Hello World!");
//GUI_intToString(TouchState.x,touchBuf);
//TEXT_SetText(hItem,touchBuf);
//hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
//TEXT_SetFont(hItem, &GUI_Font16_ASCII);
//GUI_intToString(TouchState.y,touchBuf);
//TEXT_SetText(hItem,touchBuf);
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
WM_HWIN CreateWindow(void);
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
return hWin;
}
// USER START (Optionally insert additional public code)
// USER END
/*************************** End of file ****************************/
复制代码
加载中...
查看其它2个回答
一周热门
更多
>
相关问题
相关文章
嵌入式编译生成的HEX文件和BIN文件内容详解
0个评论
ST公司第一款无线低功耗单片机模块有效提高物联网设计生产效率
0个评论
单片机中把部分Flash虚拟成Eeprom使用时,如何延长使用寿命
0个评论
如何实现对单片机寄存器的访问
0个评论
通过USB用STM32片内自带Bootloader下载程序及注意事项
0个评论
欲练此功必先自宫之STM32汇编启动,放慢是为了更好的前行
0个评论
敢问路在何方,STM32迈出的第一步,却注定了它非凡的一生
0个评论
年工作时间真的就等于3年工作经验?也许你就不配
0个评论
×
关闭
采纳回答
向帮助了您的知道网友说句感谢的话吧!
非常感谢!
确 认
×
关闭
编辑标签
最多设置5个标签!
保存
关闭
×
关闭
举报内容
检举类型
检举内容
检举用户
检举原因
广告推广
恶意灌水
回答内容与提问无关
抄袭答案
其他
检举说明(必填)
提交
关闭
×
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
×
付费偷看金额在0.1-10元之间
确定
×
关闭
您已邀请
0
人回答
查看邀请
擅长该话题的人
回答过该话题的人
我关注的人
我在窗口上放了一个按钮,但触摸该按钮时一直没反应,直接显示触摸点数据是没问题的,是不是我哪里配置有问题呀?看别的例程里都没有添加WM_TOUCH事件消息。我的代码如下,
- #include "DIALOG.h"
- #include "stdio.h"
- #include "math.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
- #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
- #define ID_BUTTON_2 (GUI_ID_USER + 0x03)
- #define ID_TEXT_1 (GUI_ID_USER + 0x04)
- #define ID_TEXT_2 (GUI_ID_USER + 0x05)
- extern GUI_CONST_STORAGE GUI_FONT GUI_FontsongFont16;
- extern int abs(int);
- // USER START (Optionally insert additional defines)
- /*void GUI_intToString(int num,char *s)
- {
- int temp,i;
- i = 0;
- if(num == 0)
- {
- *s = '0';
- }
- else if(num<0)
- {
- temp=abs(num);
- *s = '-';
- s++;
- i++;
- }
- while(num!=0)
- {
- temp=num%10;
- switch (temp){
- case 0:
- *s = '0';
- s++;
- i++;
- break;
- case 1:
- *s = '1';
- s++;
- i++;
- break;
- case 2:
- *s = '2';
- s++;
- i++;
- break;
- case 3:
- *s = '3';
- s++;
- i++;
- break;
- case 4:
- *s = '4';
- s++;
- i++;
- break;
- case 5:
- *s = '5';
- s++;
- i++;
- break;
- case 6:
- *s = '6';
- s++;
- i++;
- break;
- case 7:
- *s = '7';
- s++;
- i++;
- break;
- case 8:
- *s = '8';
- s++;
- i++;
- break;
- case 9:
- *s = '9';
- s++;
- i++;
- break;
- default :
- break;
- }
- }
- }*/
-
- // USER END
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- // USER START (Optionally insert additional static data)
- // USER END
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 400, 0, 0x0, 0 },
- { BUTTON_CreateIndirect, "Start", ID_BUTTON_0, 70, 160, 100, 40, 0, 0x0, 0 },
- { BUTTON_CreateIndirect, "Set1", ID_BUTTON_1, 70, 220, 100, 40, 0, 0x0, 0 },
- { BUTTON_CreateIndirect, "Set2", ID_BUTTON_2, 70, 280, 100, 40, 0, 0x0, 0 },
- { TEXT_CreateIndirect, "xinye", ID_TEXT_1, 80, 60, 100, 40, 0, 0x0, 0 },
- { TEXT_CreateIndirect, "Hello STemWin", ID_TEXT_2, 80, 80, 100, 40, 0, 0x0, 0 },
- // USER START (Optionally insert additional widgets)
- // USER END
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- // USER START (Optionally insert additional static code)
- void intToString(int num,char *buf)
- {
- int temp;
-
- temp = num;
- if(temp>=1000)
- temp%=1000;
-
- while(temp>0)
- {
- *buf++=temp%10;
- temp/=10;
- }
-
- }
- // USER END
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- //GUI_PID_STATE TouchState;
- static int flag = 0;
- int NCode;
- int Id;
- //char touchBuf[3];
- // USER START (Optionally insert additional variables)
- // USER END
- switch (pMsg->MsgId) {
- case WM_PAINT:
- if(!flag){
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
- TEXT_SetFont(hItem, &GUI_Font16_ASCII);
- TEXT_SetText(hItem,"Hello World!");
- }
- break;
- case WM_INIT_DIALOG:
- //
- // Initialization of 'Button'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
- //
- // Initialization of 'Button'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
- //
- // Initialization of 'Button'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
- BUTTON_SetFont(hItem, &GUI_Font16_ASCII);
- // USER START (Optionally insert additional code for further widget initialization)
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
- TEXT_SetFont(hItem, &GUI_Font16_ASCII);
- // USER END
- break;
- case WM_NOTIFY_PARENT:
- Id = WM_GetId(pMsg->hWinSrc);
- NCode = pMsg->Data.v;
- switch(Id) {
- case ID_BUTTON_0: // Notifications sent by 'Button'
- switch(NCode)
- {
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- break;
- }
- break;
- case ID_BUTTON_1:
- switch(NCode) {
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- flag = !flag;
- WM_InvalidateWindow(pMsg->hWin);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
- TEXT_SetFont(hItem, &GUI_Font16_ASCII);
- TEXT_SetText(hItem,"Hello World!");
- break;
- }
- break;
- case ID_BUTTON_2:
- switch(NCode) {
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- break;
- }
- break;
- }
- break;
- case WM_TOUCH:
- break;
- //hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
- //TEXT_SetFont(hItem, &GUI_Font16_ASCII);
- //GUI_TOUCH_GetState(&TouchState);
- //TEXT_SetText(hItem,"Hello World!");
- //GUI_intToString(TouchState.x,touchBuf);
- //TEXT_SetText(hItem,touchBuf);
-
- //hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
- //TEXT_SetFont(hItem, &GUI_Font16_ASCII);
- //GUI_intToString(TouchState.y,touchBuf);
- //TEXT_SetText(hItem,touchBuf);
- // USER START (Optionally insert additional message handling)
- // USER END
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * CreateWindow
- */
- WM_HWIN CreateWindow(void);
- WM_HWIN CreateWindow(void) {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- return hWin;
- }
- // USER START (Optionally insert additional public code)
- // USER END
- /*************************** End of file ****************************/
复制代码一周热门 更多>