完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
转stemwin教程
本期教程开始讲解STemWin的消息类型,这部分知识也非常的重要,大家可以不懂消息的通信机制,但必须的知道简单的通信过程。 33. 1 消息结构 33. 2 消息类型 33. 3 系统类型消息实例 33. 4 指针输入设备(PID)类型消息实例 33. 5 通知代码类型消息实例 33. 6 总结 33.1 消息结构 回调例程被调用时,它会收到以其pMsg参数指定的消息。此消息实际上是一个WM_MESSAGE数据结构,其元素定义如下。
|
||
相关推荐
|
||
33.3 系统类型消息实例
下面我们通过一个具体的实例来讲解系统消息类型。这里我们通过前面讲的uCGUIBulder4.0创建一个如下的对话框(关于对话框的内容会在后面的教程跟大家详细讲解)。 |
|
|
|
|
|
建立以后生成的代码如下(重点看系统消息部分)
复制代码 #include #include "GUI.h" #include "DIALOG.h" #include "WM.h" #include "BUTTON.h" #include "CHECKBOX.h" #include "DROPDOWN.h" #include "EDIT.h" #include "FRAMEWIN.h" #include "LISTBOX.h" #include "MULTIEDIT.h" #include "RADIO.h" #include "SLIDER.h" #include "TEXT.h" #include "PROGBAR.h" #include "SCROLLBAR.h" #include "LISTVIEW.h" //EventsFunctionList void OnButtonClicked(WM_MESSAGE * pMsg); void OnButtonReleased(WM_MESSAGE * pMsg); void OnButtonMovedOut(WM_MESSAGE * pMsg); //EndofEventsFunctionList /********************************************************************* * * Dialog resource * * This table conatins the info required to create the dialog. * It has been created by ucGUIbuilder. */ static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { FRAMEWIN_CreateIndirect, "armfly", 0, 0, 0, 800,480,FRAMEWIN_CF_MOVEABLE,0}, { BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 82, 122,162,37, 0,0}, { BUTTON_CreateIndirect, "BUTTON1", GUI_ID_BUTTON1, 357,123,152,35, 0,0} }; /***************************************************************** ** FunctionName:void PaintDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_PAINT *****************************************************************/ void PaintDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; } /***************************************************************** ** FunctionName:void InitDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_INIT_DIALOG *****************************************************************/ void InitDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; // //FRAMEWIN // FRAMEWIN_SetFont(hWin,&GUI_Font24B_ASCII); FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER); FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0); FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1); FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2); FRAMEWIN_SetTitleHeight(hWin,30); } /********************************************************************* * * Dialog callback routine */ static void _cbCallback(WM_MESSAGE * pMsg) { int NCode, Id; WM_HWIN hWin = pMsg->hWin; switch (pMsg->MsgId) (1) { case WM_PAINT:(2) PaintDialog(pMsg); break; case WM_INIT_DIALOG:(3) InitDialog(pMsg); break; case WM_KEY: (4) switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) { case GUI_KEY_ESCAPE: GUI_EndDialog(hWin, 1); break; case GUI_KEY_ENTER: GUI_EndDialog(hWin, 0); break; } break; case WM_NOTIFY_PARENT:(5) Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case GUI_ID_OK: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_CANCEL: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_BUTTON0: switch(NCode) { case WM_NOTIFICATION_CLICKED: OnButtonClicked(pMsg); break; case WM_NOTIFICATION_RELEASED: OnButtonReleased(pMsg); break; case WM_NOTIFICATION_MOVED_OUT: OnButtonMovedOut(pMsg); break; } break; case GUI_ID_BUTTON1: switch(NCode) { case WM_NOTIFICATION_CLICKED: OnButtonClicked(pMsg); break; case WM_NOTIFICATION_RELEASED: OnButtonReleased(pMsg); break; case WM_NOTIFICATION_MOVED_OUT: OnButtonMovedOut(pMsg); break; } break; } break; default: WM_DefaultProc(pMsg); } } /********************************************************************* * * MainTask * ********************************************************************** */ void MainTask(void) { GUI_Init(); WM_SetDesktopColor(GUI_WHITE); /* Automacally update desktop window */ WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */ //PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); //FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX); //PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); //BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); //CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX); //DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX); //SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX); //SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX); //HEADER_SetDefaultSkin(HEADER_SKIN_FLEX); //RADIO_SetDefaultSkin(RADIO_SKIN_FLEX); GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0); } |
|
|
|
|
|
这里咱们重点看对话框的回调函数_cbCallback中的内容:
1. 通过switch (pMsg->MsgId) 区分各种系统消息类型。 2. WM_PAINT: 窗口变为无效 (部分或全部)并需要绘制时,WM将此消息发送到窗口。窗口收到WM_PAINT消息时,应重绘自身。将此消息发送到窗口前,WM确保它已被选定。该消息的Data.p指针指向在屏幕坐标中包含窗口的无效矩形的GUI_RECT结构。此类信息可用于优化着色功能。 3. WM_INIT_DIALOG: 此消息在对话框创建后、显示前发送到窗口。对话框程序通常使用此消息初始化小工具,并执行影响对话框外观的其他任何初始化任务。 上面程序中初始化了控件FrameWin,主要是设置了一些标题。 4. WM_KEY: 按下某个键后发送此消息到当前包含焦点的窗体。第31章介绍键盘输入的时候就是用的这个消息。Data.p指针中含有指向WM_KEY_INFO结构的消息。WM_KEY_INFO的定义如下: 5. WM_NOTIFY_PARENT: 告知父窗口,其子窗口中发生了某些改变。这些消息通常由小工具发送到其父窗口,让它们可以对事件作出反应。消息的Data.v值包含消息的通知代码。上面对话框上创建的两个按钮就是通过这个消息进行操作。 这里我们就先介绍这几种消息,后面再介绍其余的系统消息类型。 |
|
|
|
|
|
33.4 指针输入设备(PID)类型消息实例
基于上面的例子,我们实现一下PID类型消息WM_MOUSEOVER,代码如下(可以直接复制到模拟器上面运行或者开发板上面): 复制代码 #include #include "GUI.h" #include "DIALOG.h" #include "WM.h" #include "BUTTON.h" #include "CHECKBOX.h" #include "DROPDOWN.h" #include "EDIT.h" #include "FRAMEWIN.h" #include "LISTBOX.h" #include "MULTIEDIT.h" #include "RADIO.h" #include "SLIDER.h" #include "TEXT.h" #include "PROGBAR.h" #include "SCROLLBAR.h" #include "LISTVIEW.h" /********************************************************************* * * static data * ********************************************************************** */ GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW}; (1) static unsigned char ucBackColor; (2) /********************************************************************* * * Dialog resource * * This table conatins the info required to create the dialog. * It has been created by ucGUIbuilder. */ static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { FRAMEWIN_CreateIndirect, "armfly", 0, 0, 0, 800,480,FRAMEWIN_CF_MOVEABLE,0}, { BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 82, 122,162,37, 0,0}, { BUTTON_CreateIndirect, "BUTTON1", GUI_ID_BUTTON1, 357,123,152,35, 0,0} }; /***************************************************************** ** FunctionName:void PaintDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_PAINT *****************************************************************/ void PaintDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; GUI_SetBkColor(_acColor[ucBackColor]);(3) GUI_Clear(); } /***************************************************************** ** FunctionName:void InitDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_INIT_DIALOG *****************************************************************/ void InitDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; // //FRAMEWIN // FRAMEWIN_SetFont(hWin,&GUI_Font24B_ASCII);(4) FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER); FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0); FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1); FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2); FRAMEWIN_SetTitleHeight(hWin,30); /* 默认颜色取*/ ucBackColor = 0;(5) } /********************************************************************* * * Dialog callback routine */ static void _cbCallback(WM_MESSAGE * pMsg) { int NCode, Id; WM_HWIN hWin = pMsg->hWin; switch (pMsg->MsgId) { case WM_MOUSEOVER:(6) ucBackColor++; if (ucBackColor == 3) { ucBackColor = 0; } WM_InvalidateWindow(hWin); break; case WM_PAINT: PaintDialog(pMsg); break; case WM_INIT_DIALOG: InitDialog(pMsg); break; case WM_KEY: switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) { case GUI_KEY_ESCAPE: GUI_EndDialog(hWin, 1); break; case GUI_KEY_ENTER: GUI_EndDialog(hWin, 0); break; } break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case GUI_ID_OK: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_CANCEL: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_BUTTON0: switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: break; case WM_NOTIFICATION_MOVED_OUT: break; } break; case GUI_ID_BUTTON1: switch(NCode) { case WM_NOTIFICATION_CLICKED: break; case WM_NOTIFICATION_RELEASED: break; case WM_NOTIFICATION_MOVED_OUT: break; } break; } break; default: WM_DefaultProc(pMsg); } } /********************************************************************* * * MainTask * ********************************************************************** */ void MainTask(void) { GUI_Init(); WM_SetDesktopColor(GUI_BLUE); /* Automacally update desktop window */ WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */ PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX); PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX); DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX); SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX); SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX); HEADER_SetDefaultSkin(HEADER_SKIN_FLEX); RADIO_SetDefaultSkin(RADIO_SKIN_FLEX); GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0); } |
|
|
|
|
|
1. 定义一个数组,里面有三种颜色。
2. 定义一个变量,用于上面三种颜色的切换。 3. 在WM_PAINT消息中实现重绘,主要用于实现对话框用户区的颜色重绘。 4. 在WM_INIT_DIALOG消息中初始化对话框中的控件,这里初始化了FrameWin。 5. 初始化背景颜色的初始值_acColor[ucBackColor]。 6. 这里加入了消息WM_MOUSEOVER,这个消息的功能是指针输入设备接触到窗口轮廓时发送到窗口。仅在启用鼠标支持时发送。在这个消息里面切换对话框的背景色变量,然后调用函数WM_InvalidateWindow,一旦调用这个函数就会去执行此对话框的WM_PAINT消息。 这个例子的实际显示效果如下: PID类型的其它消息,大家可以在模拟器上面做一个简单的测试,后面用到的时候还会跟大家详细讲解。 |
|
|
|
|
|
33.5 通知代码类型消息实例
这里我们还用上面创建的例子,只不过这次我们主要通过对话框上的按钮来实现这种消息类型。代码如下(可以直接复制到模拟器上面运行或者开发板上面): 复制代码 #include #include "GUI.h" #include "DIALOG.h" #include "WM.h" #include "BUTTON.h" #include "CHECKBOX.h" #include "DROPDOWN.h" #include "EDIT.h" #include "FRAMEWIN.h" #include "LISTBOX.h" #include "MULTIEDIT.h" #include "RADIO.h" #include "SLIDER.h" #include "TEXT.h" #include "PROGBAR.h" #include "SCROLLBAR.h" #include "LISTVIEW.h" /********************************************************************* * * static data * ********************************************************************** */ GUI_COLOR _acColor[3] = {GUI_BLUE,GUI_RED,GUI_YELLOW}; static char ucBackColor; /********************************************************************* * * Dialog resource * * This table conatins the info required to create the dialog. * It has been created by ucGUIbuilder. */ static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { FRAMEWIN_CreateIndirect, "armfly", 0, 0, 0, 800,480,FRAMEWIN_CF_MOVEABLE,0}, { BUTTON_CreateIndirect, "BUTTON0", GUI_ID_BUTTON0, 82, 122,162,37, 0,0}, { BUTTON_CreateIndirect, "BUTTON1", GUI_ID_BUTTON1, 357,123,152,35, 0,0} }; /***************************************************************** ** FunctionName:void PaintDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_PAINT *****************************************************************/ void PaintDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; GUI_SetBkColor(_acColor[ucBackColor]); GUI_Clear(); } /***************************************************************** ** FunctionName:void InitDialog(WM_MESSAGE * pMsg) ** Function: to initialize the Dialog items ** ** call this function in _cbCallback --> WM_INIT_DIALOG *****************************************************************/ void InitDialog(WM_MESSAGE * pMsg) { WM_HWIN hWin = pMsg->hWin; // //FRAMEWIN // FRAMEWIN_SetFont(hWin,&GUI_Font24B_ASCII); FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER); FRAMEWIN_AddCloseButton(hWin, FRAMEWIN_BUTTON_RIGHT, 0); FRAMEWIN_AddMaxButton(hWin, FRAMEWIN_BUTTON_RIGHT, 1); FRAMEWIN_AddMinButton(hWin, FRAMEWIN_BUTTON_RIGHT, 2); FRAMEWIN_SetTitleHeight(hWin,30); /* 默认颜色取*/ ucBackColor = 0; } /********************************************************************* * * Dialog callback routine */ static void _cbCallback(WM_MESSAGE * pMsg) { int NCode, Id; WM_HWIN hWin = pMsg->hWin; switch (pMsg->MsgId) { case WM_MOUSEOVER: break; case WM_PAINT: PaintDialog(pMsg); break; case WM_INIT_DIALOG: InitDialog(pMsg); break; case WM_KEY: switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) { case GUI_KEY_ESCAPE: GUI_EndDialog(hWin, 1); break; case GUI_KEY_ENTER: GUI_EndDialog(hWin, 0); break; } break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case GUI_ID_OK: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_CANCEL: if(NCode==WM_NOTIFICATION_RELEASED) GUI_EndDialog(hWin, 0); break; case GUI_ID_BUTTON0: switch(NCode) { case WM_NOTIFICATION_CLICKED:(1) ucBackColor++; if (ucBackColor == 3) { ucBackColor = 0; } WM_InvalidateWindow(hWin); break; case WM_NOTIFICATION_RELEASED: break; case WM_NOTIFICATION_MOVED_OUT: break; } break; case GUI_ID_BUTTON1: switch(NCode) { case WM_NOTIFICATION_CLICKED:(2) ucBackColor--; if (ucBackColor < 0) { ucBackColor = 2; } WM_InvalidateWindow(hWin); break; case WM_NOTIFICATION_RELEASED: break; case WM_NOTIFICATION_MOVED_OUT: break; } break; } break; default: WM_DefaultProc(pMsg); } } /********************************************************************* * * MainTask * ********************************************************************** */ void MainTask(void) { GUI_Init(); WM_SetDesktopColor(GUI_BLUE); /* Automacally update desktop window */ WM_SetCreateFlags(WM_CF_MEMDEV); /* Use memory devices on all windows to avoid flicker */ PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX); PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX); BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX); CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX); DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX); SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX); SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX); HEADER_SetDefaultSkin(HEADER_SKIN_FLEX); RADIO_SetDefaultSkin(RADIO_SKIN_FLEX); GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0); } |
|
|
|
|
|
1. 这里主要是实现按钮的WM_NOTIFICATION_CLICKED消息。如果用户按下这个按钮,那么就切换背景颜色。
2. 同上,只不过这里用的是另一个按钮。 3. 实际显示效果和上面33.4小节的贴图是一样的。 |
|
|
|
|
|
33.6 总结
本期教程就跟大家讲这么多,只给大家具了部分消息类型的通信实例,后面还会通过更多例子来强化大家对这方面知识的理解。 |
|
|
|
|
|
417 浏览 0 评论
430 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
393 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
974 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1055 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11771 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 22:19 , Processed in 0.833166 second(s), Total 93, Slave 75 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号