本帖最后由 captainabc1 于 2023-6-8 16:57 编辑
emWin 新手入门学习笔记 (2)
续学习笔记(1)…… 4 简单解析自动生成的界面代码 设计的界面生成的 FramewinDLG.C程序是个啥模样?(请参见附件程序清单)。 下面从3方面简单解析,不妥之处恳请网友指出。 (1) 与控件尺寸、位置相关的数值信息 看下这几行: - static const GUI_WIDGET_CREATE_INFO_aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect,"Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 0, 0x64, 0 },
- {BUTTON_CreateIndirect, "ON", ID_BUTTON_0, 60, 100, 80, 38, 0, 0x0, 0},
复制代码 我画了图1这张图,可对照着看一下。在用GUIBuilderV5.46 工具设计这个界面时, 选中ON按钮控件,可看到:xPos=60; yPos=100; xSize=80; ySize=38;这些数值的含
义是显而易见的。需要注意的是yPos=100;这个值,是由Y0=0处算起的值,而不是由屏幕
的原点算起的,而Y0值(相对屏幕原点)大小与你选择的窗口标题字的大小相关联。
图1 程序中控件数据信息与界面图形的对应关系图
(2)与用户程序执行功能相关的消息代码 - switch(NCode) {
- case WM_NOTIFICATION_CLICKED: //ON按钮按下
- // USER START (Optionally insert code for reacting on notificationmessage)
- // USER END //笔者注:用户在此可插入自己对通知消息进行响应的代码
- break;
- case WM_NOTIFICATION_RELEASED: //ON按钮弹起
- // USER START (Optionally insert code for reacting on notificationmessage)
- // USER END
- break;
复制代码 对于OFF按钮对应的代码与此类似。
(3) 与GUI函数库相关联的信息 用#define来对函数进行“定义”,将界面设计的控件与GUI的库函数联系起来, 以实现在用户屏幕显示设计的界面。 - #define ID_FRAMEWIN_0 (GUI_ID_USER+ 0x00)
- #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
- #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
- #define ID_TEXT_0 (GUI_ID_USER + 0x03)
复制代码 据资料介绍,GUI的库函数是以.lib的形式提供给用户使用,其代码是不开源的, 喜欢深入钻研的网友,可去看emWin的前身uCGUI,这个是开源的。 5 自动生成的界面代码怎么用? 笔者界面用两个按钮来控制LED灯的亮灭。对于生成的程序,只需将它复制、粘贴 到用户程序中,在ON及OFF按钮后面,分别插入LED灯亮、灯灭的代码,然后在MDK5(Keil5) 开发环境下,编译调试后,即可运行! 对于较复杂、绚丽的界面,相对就麻烦些,STemWin 这个软件包提供了模拟器 这个工具(SimulationTrial),可在电脑中仿真、调试,运行通过后,再放到单片机 中去用。
- 笔记附件程序清单:
- /*********************************************************************
- * *
- * SEGGER Microcontroller GmbH & Co. KG *
- * Solutions for real time microcontroller applications *
- * *
- **********************************************************************
- * *
- * C-file generated by: *
- * *
- * GUI_Builder for emWin version 5.46 *
- * Compiled Dec 12 2017, 16:38:40 *
- * (c) 2017 Segger Microcontroller GmbH & Co. KG *
- * *
- **********************************************************************
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- */
- // USER START (Optionally insert additional includes)
- // USER END
- #include "DIALOG.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_FRAMEWIN_0 (GUI_ID_USER + 0x00)
- #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
- #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
- #define ID_TEXT_0 (GUI_ID_USER + 0x03)
- // USER START (Optionally insert additional defines)
- // USER END
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- // USER START (Optionally insert additional static data)
- // USER END
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_0, 0, 0, 320, 240, 0, 0x64, 0 },
- { BUTTON_CreateIndirect, "ON", ID_BUTTON_0, 60, 100, 80, 38, 0, 0x0, 0 },
- { BUTTON_CreateIndirect, "OFF", ID_BUTTON_1, 180, 100, 80, 38, 0, 0x0, 0 },
- { TEXT_CreateIndirect, "LED_Control", ID_TEXT_0, 101, 47, 108, 28, 0, 0x0, 0 },
- // USER START (Optionally insert additional widgets)
- // USER END
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- // USER START (Optionally insert additional static code)
- // USER END
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- int NCode;
- int Id;
- // USER START (Optionally insert additional variables)
- // USER END
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Initialization of 'Framewin'
- //
- hItem = pMsg->hWin;
- FRAMEWIN_SetText(hItem, "STemWin_Study_1");
- FRAMEWIN_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
- FRAMEWIN_SetFont(hItem, GUI_FONT_20_ASCII);
- //
- // Initialization of 'ON'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
- BUTTON_SetFont(hItem, GUI_FONT_20_ASCII);
- //
- // Initialization of 'OFF'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
- BUTTON_SetFont(hItem, GUI_FONT_20_ASCII);
- //
- // Initialization of 'LED_Control'
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
- TEXT_SetFont(hItem, GUI_FONT_20_ASCII);
- // USER START (Optionally insert additional code for further widget initialization)
- // 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 'ON'
- 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)
- // USER END
- break;
- // USER START (Optionally insert additional code for further notification handling)
- // USER END
- }
- break;
- case ID_BUTTON_1: // Notifications sent by 'OFF'
- 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)
- // 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)
- // USER END
- }
- break;
- // USER START (Optionally insert additional message handling)
- // USER END
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * CreateFramewin
- */
- WM_HWIN CreateFramewin(void);
- WM_HWIN CreateFramewin(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 ****************************/
复制代码
|