300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > EmWin自定义消息发送

EmWin自定义消息发送

时间:2023-12-29 00:38:25

相关推荐

EmWin自定义消息发送

例如我要定义一个WM_IC的消息

1.在emwin窗口文件的头文件.h文件中声明 #define WM_IC (WM_USER + 0x00)//自定义消息

2.然后在 switch (pMsg->MsgId) {…}中定义一个case WM_IC:…break;

然后就是想在地方产生此消息用WM_SendMessageNoPara(WM_GetClientWindow(hDlg),WM_IC)即可

其中WM_GetClientWindow为返回客户端窗口句柄。具体在《emWin5中文手册》窗口管理器(WM)中14.5WM API这一节中。

#include "DIALOG.h"#include "3DDLG.h"#include "EmWinHZFont.h"#include "shezhi_winDLG.h"#include "delay.h"#include "led.h"#include "rc522.h"#include "tftlcd.h"#include "ltdc.h"/*********************************************************************** Defines************************************************************************/#define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)#define ID_BUTTON_1 (GUI_ID_USER + 0x01)//设置 3#define ID_BUTTON_2 (GUI_ID_USER + 0x02)//主页 4#define ID_BUTTON_3 (GUI_ID_USER + 0x03)//配置 5#define ID_BUTTON_4 (GUI_ID_USER + 0x04)//状态 1#define ID_BUTTON_5 (GUI_ID_USER + 0x05)//位置 2#define ID_BUTTON_6 (GUI_ID_USER + 0x06)//位置 2#define ID_TEXT_1 (GUI_ID_USER + 0x07)//打印机温度#define ID_TEXT_2 (GUI_ID_USER + 0x08)//打印机温度#define ID_TEXT_3 (GUI_ID_USER + 0x09)//打印机温度static int m=1,n=0;//m为行,n为列BUTTON_SKINFLEX_PROPS Props1;u8 flag1=1,flag2=1,flag3=1;char IC_buf0[2];char IC_buf1[2];char IC_buf2[2];char IC_buf3[2];/**********外部变量声明***************/extern u16 info;extern unsigned char IC_SN[4]; //卡号 extern u8 RS485buf[80];extern u8 show_IC;/**********外部变量声明***************/const FRAMEWIN_SKINFLEX_PROPS pProps={ GUI_WHITE,GUI_WHITE,GUI_WHITE,GUI_WHITE,GUI_WHITE,0,5,5,5,1,5,};static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {{ FRAMEWIN_CreateIndirect, "3D", ID_FRAMEWIN_0, 0, 0, 480, 272, 0, 0x0, 0 },{ BUTTON_CreateIndirect, "Button", ID_BUTTON_1, 0, 0, 470, 86, 0, 0x0, 0 },//{ BUTTON_CreateIndirect, "Button", ID_BUTTON_2, 160, 86, 160, 87, 0, 0x0, 0 },//{ BUTTON_CreateIndirect, "Button", ID_BUTTON_3, 320, 86, 160, 87, 0, 0x0, 0}, //{ BUTTON_CreateIndirect, "Button", ID_BUTTON_4, 0, 173, 160, 62, 0, 0x0, 0 },//{ BUTTON_CreateIndirect, "Button", ID_BUTTON_5, 160, 173, 160, 62, 0, 0x0, 0 },//{ BUTTON_CreateIndirect, "Button", ID_BUTTON_6, 320, 173, 160, 62, 0, 0x0, 0},//{ TEXT_CreateIndirect, "Text", ID_TEXT_1, 60, 20, 26, 20, 0, 0x64, 0 }, { TEXT_CreateIndirect, "Text", ID_TEXT_2, 80, 20, 160, 50, 0, 0x0, 0 },{ TEXT_CreateIndirect, "Text", ID_TEXT_3, 310, 55, 26, 20, 0, 0x64, 0 },};static void _cbDialog(WM_MESSAGE * pMsg) {WM_HWIN hItem,hItem1,hItem2,hItem3,hItem4,hItem5;WM_HWIN hText1,hText2,hText3;hItem1= WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); hItem2= WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);hItem3= WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);hItem4= WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);hItem5= WM_GetDialogItem(pMsg->hWin, ID_BUTTON_6);hText1=WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);hText2=WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);hText3=WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);WM_HWIN XZ_hItem[2][2]={hItem2,hItem3,hItem4,hItem5};//button1,intNCode;intId;switch (pMsg->MsgId) {case WM_INIT_DIALOG:hItem = pMsg->hWin;FRAMEWIN_SetSkinFlexProps(&pProps,FRAMEWIN_SKINFLEX_PI_ACTIVE);BUTTON_GetSkinFlexProps(&Props1, BUTTON_SKINFLEX_PI_FOCUSSED);Props1.aColorFrame[0] = 0x007FB13C;Props1.aColorFrame[1] = 0x008FfF8F;Props1.aColorFrame[2] = 0x008FfF8F;Props1.aColorUpper[0]=0x008FfF8F;Props1.aColorUpper[1]=0x008FfF8F;Props1.aColorLower[0]=0x008FfF8F;Props1.aColorLower[1]=0x008FfF8F;Props1.Radius = 6;BUTTON_SetSkinFlexProps(&Props1, BUTTON_SKINFLEX_PI_FOCUSSED);//被选中之后的颜色FRAMEWIN_SetTextColor(hItem,GUI_BLACK);FRAMEWIN_SetTextAlign(hItem, GUI_TA_LEFT);FRAMEWIN_SetTitleHeight(hItem, 30);FRAMEWIN_SetFont(hItem, &GUI_FontHZ24);FRAMEWIN_SetText(hItem, "welcome");TEXT_SetFont(hText1, &GUI_Font16B_1);TEXT_SetText(hText1,"ID:");TEXT_SetFont(hText2, &GUI_Font16B_1); TEXT_SetText(hText2," "); //初始化BUTTON1hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);BUTTON_SetText(hItem, "");//初始化BUTTON2hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);WM_SetFocus(hItem2);BUTTON_SetText(hItem, "");////初始化BUTTON3hItem = WM_GetDialogItem(pMsg->hWin,ID_BUTTON_3);BUTTON_SetFocussable(hItem,1);BUTTON_SetText(hItem, "");//初始化 BUTTON4//hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_4);BUTTON_SetText(hItem, ""); //初始化BUTTON5hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_5);BUTTON_SetText(hItem, "");//初始化BUTTON6hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_6);BUTTON_SetText(hItem, "");break;case WM_KEY://按键控制switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) {case GUI_KEY_UP:m--;if(m<0) m=0;WM_SetFocus(XZ_hItem[m][n]);break;case GUI_KEY_DOWN:m++;if(m>1) m=1;WM_SetFocus(XZ_hItem[m][n]);break;case GUI_KEY_LEFT:n--;if(n<0) n=0;WM_SetFocus(XZ_hItem[m][n]);break;case GUI_KEY_RIGHT:n++;if(n>1) n=1;WM_SetFocus(XZ_hItem[m][n]);break;case GUI_KEY_END:GUI_EndDialog(pMsg->hWin, 0);Createsehzhi_win();}break;case WM_IC:if(show_IC){sprintf((char*)IC_buf0,"%0x",IC_SN[0]);sprintf((char*)IC_buf1,"%0x",IC_SN[1]);sprintf((char*)IC_buf2,"%0x",IC_SN[2]);sprintf((char*)IC_buf3,"%0x",IC_SN[3]);TEXT_SetFont(hText1, &GUI_Font16B_1);TEXT_SetText(hText1,"ID:");TEXT_SetFont(hText2, &GUI_Font16B_1); TEXT_SetText(hText2,IC_buf0); }else{TEXT_SetText(hText1,"ID:");TEXT_SetText(hText2," ");}break;default:WM_DefaultProc(pMsg);break;}}/*********************************************************************** Public code************************************************************************//*********************************************************************** Create3D*/WM_HWIN Create3D(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)/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。