emwin之错误使用控件函数导致死机现象

@2018-10-15

导致死机的代码示例如下

 1 /**
 2  * @brief    widget ID define
 3  * @{
 4  */
 5  
 6 #define ID_WINDOW_0                  (GUI_ID_USER + 0x00)
 7 #define ID_TEXT_0                      (GUI_ID_USER + 0x01)
 8 #define ID_TEXT_1                      (GUI_ID_USER + 0x02)
 9 #define ID_EDIT_0                      (GUI_ID_USER + 0x03)
10 #define ID_EDIT_1                      (GUI_ID_USER + 0x04)
11 #define ID_TEXT_2                      (GUI_ID_USER + 0x05)
12 #define ID_BUTTON_0                  (GUI_ID_USER + 0x06)
13  
14 /**
15  * @}
16  */ 
17 
18 
19 
20 /**
21  * @brief    widget resource list
22  * @{
23  */ 
24  
25 static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
26   { WINDOW_CreateIndirect, "factoryWindow", ID_WINDOW_0, 0, 0, 790, 424, 0, 0x0, 0 },
27   { TEXT_CreateIndirect, "ex-factory date", ID_TEXT_0, 55, 45, 100, 25, 0, 0x64, 0 },
28   { TEXT_CreateIndirect, "ex-factory number", ID_TEXT_1, 55, 85, 100, 25, 0, 0x64, 0 },
29   { EDIT_CreateIndirect, "9999-99-99", ID_EDIT_0, 160, 48, 80, 20, 0, 0x64, 0 },
30   { EDIT_CreateIndirect, "123456789", ID_EDIT_1, 160, 88, 80, 20, 0, 0x64, 0 },
31   { TEXT_CreateIndirect, "Factory Version", ID_TEXT_2, 15, 15, 120, 25, 0, 0x64, 0 },
32   { BUTTON_CreateIndirect, "Back", ID_BUTTON_0, 700, 380, 80, 35, 0, 0x0, 0 },
33   // USER START (Optionally insert additional widgets)
34   // USER END
35 };
36 
37 
38 static void _cbDialog(WM_MESSAGE * pMsg) {
39   WM_HWIN hItem;
40   int     NCode;
41   int     Id;
42   // USER START (Optionally insert additional variables)
43   // USER END
44 
45   switch (pMsg->MsgId) {
46     case WM_INIT_DIALOG:
47         //
48         // Initialization of 'ex-factory date'
49         //
50         hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
51         TEXT_SetText(hItem, "出厂日期");
52         TEXT_SetFont(hItem, &GUI_FontHZ16);
53         TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
54         //
55         // Initialization of 'ex-factory number'
56         //
57         hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
58         TEXT_SetText(hItem, "出厂编号");
59         TEXT_SetFont(hItem, &GUI_FontHZ16);
60         TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
61         
62         EDIT_SetText(hItem, "出厂编号");
63         EDIT_SetTextAlign(hItem, &GUI_FontHZ16);
64         EDIT_SetFont(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
65         //
66         // Initialization of '9999-99-99'
67         //
68         hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
69         EDIT_SetText(hItem, "9999-99-99");
70         EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
71         EDIT_SetFont(hItem, GUI_FONT_16_1);
72         //
73         // Initialization of '123456789'
74         //
75         hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
76         EDIT_SetText(hItem, "123456789");
77         EDIT_SetFont(hItem, GUI_FONT_16_1);
78         EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
79         
80         TEXT_SetText(hItem, "123456789");
81         TEXT_SetFont(hItem, GUI_FONT_16_1);
82         TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
83         //
84         // Initialization of 'Factory Version'
85         //
86         hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
87         TEXT_SetText(hItem, "出厂信息");
88         TEXT_SetFont(hItem, &GUI_FontHZ16);
89         TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
90         //
91         // Initialization of 'Back'
92         //
93         hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
94         BUTTON_SetText(hItem, "返回");
95         BUTTON_SetFont(hItem, &GUI_FontHZ24);
96         // USER START (Optionally insert additional code for further widget initialization)
97         // USER END    
98         break;
99     

上段code中红色代码为控件函数误用,即TEXT控件的initialize部分使用了EDIT控件的函数,EDIT控件的initialize部分使用了TEXT控件的函数,这种情况编译器不会报警,但实际操作现象出现死机

 

转载于:https://www.cnblogs.com/skullboyer/p/9790097.html

你可能感兴趣的:(emwin之错误使用控件函数导致死机现象)