硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4258|回复: 4
收起左侧

[emWin] 如何实现点击EDIT后弹出一个对话框

[复制链接]

16

主题

16

回帖

16

积分

新手上路

积分
16
发表于 2015-4-18 08:21:15 | 显示全部楼层 |阅读模式
我想实现的功能是点击EDIT后能弹出一个对话框,再次点击时关闭对话框,我的程序如下:

/*********************************************************************
*                                                                    *
*                SEGGER Microcontroller GmbH & Co. KG                *
*        Solutions for real time microcontroller applications        *
*                                                                    *
**********************************************************************
*                                                                    *
* C-file generated by:                                               *
*                                                                    *
*        GUI_Builder for emWin version 5.22                          *
*        Compiled Jul  4 2013, 15:16:01                              *
*        (c) 2013 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_WINDOW_0     (GUI_ID_USER + 0x00)
#define ID_BUTTON_0     (GUI_ID_USER + 0x01)
#define ID_EDIT_0     (GUI_ID_USER + 0x02)
#define ID_FRAMEWIN_0     (GUI_ID_USER + 0x03)
#define ID_BUTTON_1     (GUI_ID_USER + 0x04)

// 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[] = {
  { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 24, 0, 271, 479, 0, 0x0, 0 },
  { EDIT_CreateIndirect, "Edit", ID_EDIT_0, 83, 87, 80, 20, 0, 0x64, 0 },
  // USER START (Optionally insert additional widgets)
  // USER END
};
static const GUI_WIDGET_CREATE_INFO _aDialogCreate2[] = {
  { FRAMEWIN_CreateIndirect, "408", ID_FRAMEWIN_0, 50, 150, 100, 100, 0, 0x64, 0 },
    { BUTTON_CreateIndirect, "1", ID_BUTTON_1, 10, 10, 43, 20, 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;
    WM_HWIN hWin2;
  int     NCode;
  int     Id;
    static unsigned char i;
  // USER START (Optionally insert additional variables)
  // USER END

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
    //
    // Initialization of 'Edit'
    //
    hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
    EDIT_SetDecMode(hItem,600,0,10000,0,0);
//    WIDGET_SetEffect(hItem, DEFAULT_WIDGET_EFFECT);
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case ID_EDIT_0: // Notifications sent by 'Edit'
      switch(NCode) {
      case WM_NOTIFICATION_CLICKED:
                 i=!i;
                if(i)
                 {
                    hWin2 = GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), NULL,0, 0, 0);
                }
             else
                     GUI_EndDialog(hWin2, 0);
//                EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, ID_EDIT_0), 23);
        // 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;
      case WM_NOTIFICATION_VALUE_CHANGED:
        // 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
*
**********************************************************************
*/
/*********************************************************************
*
*       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 ****************************/
但现象是我一点击EDIT他能弹出对话框,但弹出之后马上就死机了,有没有人知道为什么?谢谢了!
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115749
QQ
发表于 2015-4-18 22:59:24 | 显示全部楼层
怎么还是犯这个错误,创建的对话框句柄是局部变量:    WM_HWIN hWin2;
回复

使用道具 举报

16

主题

16

回帖

16

积分

新手上路

积分
16
 楼主| 发表于 2015-4-19 12:18:42 | 显示全部楼层

回 eric2013 的帖子

eric2013:怎么还是犯这个错误,创建的对话框句柄是局部变量:    WM_HWIN hWin2; (2015-04-18 22:59) 
不好意思版主,有点懵了,不过我改成static WM_HWIN hWin2;他还是不行的,还是会卡死的
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115749
QQ
发表于 2015-4-20 22:20:57 | 显示全部楼层
看来你真的是使用局部变量使用习惯了,能不能把变量i也设置成全局变量。修改后就没有问题了,完整代码如下,在模拟器上面可以正常运行:
dd.gif

  1. /*********************************************************************
  2. *                SEGGER Microcontroller GmbH & Co. KG                *
  3. *        Solutions for real time microcontroller applications        *
  4. **********************************************************************
  5. *                                                                    *
  6. *        (c) 1996 - 2015  SEGGER Microcontroller GmbH & Co. KG       *
  7. *                                                                    *
  8. *        Internet: www.segger.com    Support:  support@segger.com    *
  9. *                                                                    *
  10. **********************************************************************
  11. ** emWin V5.28 - Graphical user interface for embedded applications **
  12. emWin is protected by international copyright laws.   Knowledge of the
  13. source code may not be used to write a similar product.  This file may
  14. only  be used  in accordance  with  a license  and should  not be  re-
  15. distributed in any way. We appreciate your understanding and fairness.
  16. ----------------------------------------------------------------------
  17. File        : GUIDEMO_Start.c
  18. Purpose     : GUIDEMO initialization
  19. ----------------------------------------------------------------------
  20. */
  21. #include "GUI.h"
  22. /*********************************************************************
  23. *                                                                    *
  24. *                SEGGER Microcontroller GmbH & Co. KG                *
  25. *        Solutions for real time microcontroller applications        *
  26. *                                                                    *
  27. **********************************************************************
  28. *                                                                    *
  29. * C-file generated by:                                               *
  30. *                                                                    *
  31. *        GUI_Builder for emWin version 5.22                          *
  32. *        Compiled Jul  4 2013, 15:16:01                              *
  33. *        (c) 2013 Segger Microcontroller GmbH & Co. KG               *
  34. *                                                                    *
  35. **********************************************************************
  36. *                                                                    *
  37. *        Internet: www.segger.com  Support: support@segger.com       *
  38. *                                                                    *
  39. **********************************************************************
  40. */
  41. // USER START (Optionally insert additional includes)
  42. // USER END
  43. #include "DIALOG.h"
  44. /*********************************************************************
  45. *
  46. *       Defines
  47. *
  48. **********************************************************************
  49. */
  50. #define ID_WINDOW_0     (GUI_ID_USER + 0x00)
  51. #define ID_BUTTON_0     (GUI_ID_USER + 0x01)
  52. #define ID_EDIT_0     (GUI_ID_USER + 0x02)
  53. #define ID_FRAMEWIN_0     (GUI_ID_USER + 0x03)
  54. #define ID_BUTTON_1     (GUI_ID_USER + 0x04)
  55. // USER START (Optionally insert additional defines)
  56. // USER END
  57. /*********************************************************************
  58. *
  59. *       Static data
  60. *
  61. **********************************************************************
  62. */
  63. // USER START (Optionally insert additional static data)
  64. // USER END
  65. /*********************************************************************
  66. *
  67. *       _aDialogCreate
  68. */
  69. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  70.   { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 24, 0, 271, 479, 0, 0x0, 0 },
  71.   { EDIT_CreateIndirect, "Edit", ID_EDIT_0, 83, 87, 80, 20, 0, 0x64, 0 },
  72.   // USER START (Optionally insert additional widgets)
  73.   // USER END
  74. };
  75. static const GUI_WIDGET_CREATE_INFO _aDialogCreate2[] = {
  76.   { FRAMEWIN_CreateIndirect, "408", ID_FRAMEWIN_0, 50, 150, 100, 100, 0, 0x64, 0 },
  77.     { BUTTON_CreateIndirect, "1", ID_BUTTON_1, 10, 10, 43, 20, 0, 0x0, 0 },
  78.   // USER START (Optionally insert additional widgets)
  79.   // USER END
  80. };
  81. /*********************************************************************
  82. *
  83. *       Static code
  84. *
  85. **********************************************************************
  86. */
  87. // USER START (Optionally insert additional static code)
  88. // USER END
  89. /*********************************************************************
  90. *
  91. *       _cbDialog
  92. */
  93. WM_HWIN hWin2;
  94. static unsigned char i = 0;
  95. static void _cbDialog(WM_MESSAGE * pMsg) {
  96.   WM_HWIN hItem;
  97.    
  98.   int     NCode;
  99.   int     Id;
  100.    
  101.   // USER START (Optionally insert additional variables)
  102.   // USER END
  103.   switch (pMsg->MsgId) {
  104.   case WM_INIT_DIALOG:
  105.     //
  106.     // Initialization of 'Edit'
  107.     //
  108.     hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
  109.     EDIT_SetDecMode(hItem,600,0,10000,0,0);
  110. //    WIDGET_SetEffect(hItem, DEFAULT_WIDGET_EFFECT);
  111.     break;
  112.   case WM_NOTIFY_PARENT:
  113.     Id    = WM_GetId(pMsg->hWinSrc);
  114.     NCode = pMsg->Data.v;
  115.     switch(Id) {
  116.     case ID_EDIT_0: // Notifications sent by 'Edit'
  117.       switch(NCode) {
  118.       case WM_NOTIFICATION_CLICKED:
  119.                  i=!i;
  120.                 if(i)
  121.                  {
  122.                     hWin2 = GUI_CreateDialogBox(_aDialogCreate2, GUI_COUNTOF(_aDialogCreate2), NULL,0, 0, 0);
  123.                 }
  124.              else
  125.                      GUI_EndDialog(hWin2, 0);
  126. //                EDIT_SetValue(WM_GetDialogItem(pMsg->hWin, ID_EDIT_0), 23);
  127.         // USER START (Optionally insert code for reacting on notification message)
  128.         // USER END
  129.         break;
  130.       case WM_NOTIFICATION_RELEASED:
  131.         // USER START (Optionally insert code for reacting on notification message)
  132.         // USER END
  133.         break;
  134.       case WM_NOTIFICATION_VALUE_CHANGED:
  135.         // USER START (Optionally insert code for reacting on notification message)
  136.         // USER END
  137.         break;
  138.       // USER START (Optionally insert additional code for further notification handling)
  139.       // USER END
  140.       }
  141.       break;
  142.     // USER START (Optionally insert additional code for further Ids)
  143.     // USER END
  144.     }
  145.     break;
  146.   // USER START (Optionally insert additional message handling)
  147.   // USER END
  148.   default:
  149.     WM_DefaultProc(pMsg);
  150.     break;
  151.   }
  152. }
  153. /*********************************************************************
  154. *
  155. *       Public code
  156. *
  157. **********************************************************************
  158. */
  159. /*********************************************************************
  160. *
  161. *       CreateWindow
  162. */
  163. WM_HWIN CreateWindow(void);
  164. WM_HWIN CreateWindow(void) {
  165.   WM_HWIN hWin;
  166.   hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  167.   return hWin;
  168. }
  169. // USER START (Optionally insert additional public code)
  170. // USER END
  171. void MainTask(void)
  172. {
  173.   GUI_Init();
  174. CreateWindow();
  175.     while(1)
  176. {
  177.   GUI_Delay(20);
  178. }
  179. }
  180. /*************************** End of file ****************************/
复制代码
回复

使用道具 举报

11

主题

104

回帖

137

积分

初级会员

积分
137
发表于 2017-7-19 11:34:37 | 显示全部楼层

回 eric2013 的帖子

eric2013:看来你真的是使用局部变量使用习惯了,能不能把变量i也设置成全局变量。修改后就没有问题了,完整代码如下,在模拟器上面可以正常运行:


/*********************************************************************
*        .. (2015-04-20 22:20) 
[s:151][s:151][s:151]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-15 12:44 , Processed in 0.244611 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表