硬汉嵌入式论坛

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

[emWin] 两个listbox同时显示文本的问题???

[复制链接]

1

主题

4

回帖

1

积分

新手上路

积分
1
发表于 2017-8-10 15:07:29 | 显示全部楼层 |阅读模式

上位机模拟

上位机模拟
微信图片_20170810145836.jpg


如上图所示,上位机模拟创建三个控件,两个listbox和一个scroll,上位机模拟的两个listbox都可以显示文本,单片机端不可以?不知道为什么
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117635
QQ
发表于 2017-8-10 17:22:50 | 显示全部楼层
这个是OLED吗,方便的话,贴下emWin应用部分的代码,代码没问题的话,有可能是底层移植有些问题,另外就是换成EDIT控件测试下是否有问题。
回复

使用道具 举报

1

主题

4

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2017-8-11 09:42:38 | 显示全部楼层
嗯 是OLED,移植参考你那篇   OLED上面移植STemWin5.20应用代码如下,谢谢版主
  1. /*********************************************************************
  2. *                                                                    *
  3. *                SEGGER Microcontroller GmbH & Co. KG                *
  4. *        Solutions for real time microcontroller applications        *
  5. *                                                                    *
  6. **********************************************************************
  7. *                                                                    *
  8. * C-file generated by:                                               *
  9. *                                                                    *
  10. *        GUI_Builder for emWin version 5.32                          *
  11. *        Compiled Oct  8 2015, 11:59:02                              *
  12. *        (c) 2015 Segger Microcontroller GmbH & Co. KG               *
  13. *                                                                    *
  14. **********************************************************************
  15. *                                                                    *
  16. *        Internet: www.segger.com  Support: support@segger.com       *
  17. *                                                                    *
  18. **********************************************************************
  19. */
  20. // USER START (Optionally insert additional includes)
  21. // USER END
  22. //#include "DIALOG.h"
  23. //#include "MainTask.h"
  24. #include "GUI.h"
  25. #include "WM.h"
  26. #include "BUTTON.h"
  27. #include "CHECKBOX.h"
  28. #include "DROPDOWN.h"
  29. #include "EDIT.h"
  30. #include "FRAMEWIN.h"
  31. #include "LISTBOX.h"
  32. #include "MULTIEDIT.h"
  33. #include "RADIO.h"
  34. #include "SLIDER.h"
  35. #include "TEXT.h"
  36. #include "PROGBAR.h"
  37. #include "SCROLLBAR.h"
  38. #include "LISTVIEW.h"
  39. #include "GRAPH.h"
  40. #include "MENU.h"
  41. #include "MULTIPAGE.h"
  42. #include "ICONVIEW.h"
  43. #include "TREEVIEW.h"
  44. #include <stdlib.h>
  45. #include "stddef.h"
  46. /*********************************************************************
  47. *
  48. *       Defines
  49. *
  50. **********************************************************************
  51. */
  52. #define ID_FRAMEWIN_0    (GUI_ID_USER + 0x00)
  53. #define ID_SCROLLBAR_0   (GUI_ID_USER + 0x01)
  54. #define ID_LISTBOX_0     (GUI_ID_USER + 0x02)
  55. #define ID_LISTBOX_1     (GUI_ID_USER + 0x03)
  56. // #define WM_UP_FOCUS      (WM_USER + 0x00)
  57. // #define WM_DOWN_FOCUS    (WM_USER + 0x01)
  58. // #define MSG_NextMusic    (WM_USER + 0x32)
  59. #define ID_TIMER_HSCROLL      0
  60. #define ID_TIMER_ADD_WIFIAP   1
  61. #define TOTAL_ITEMS           20
  62. #define WM_UP_FOCUS      (WM_USER + 0x00)
  63. #define WM_DOWN_FOCUS    (WM_USER + 0x01)
  64. typedef enum {LEFT_SCROLL = 0, RIGHT_SCROLL = !LEFT_SCROLL} dir_scroll_enum;
  65. dir_scroll_enum dir_scroll = RIGHT_SCROLL;
  66. typedef char uint8_t;
  67. typedef struct message_wifi_ap
  68. {
  69.         uint8_t encryption;         // wifi-ap Encryption
  70.         uint8_t name[20];           // wifi-ap ssid
  71.         uint8_t rssi;               // wifi-ap rssi
  72.         uint8_t mac[17];            // wifi-ap MAC address
  73.         uint8_t ch;                 // wifi-ap ch
  74.         uint8_t freq_offset;        // wifi-ap freq_offset
  75.         uint8_t freq_calibration;   // wifi-ap freq_calibration
  76. }message_wifi_ap_def;
  77. // USER START (Optionally insert additional defines)
  78. // USER END
  79. message_wifi_ap_def *p_message_display_wifi_ap = NULL;
  80. message_wifi_ap_def message_display_wifi_ap[TOTAL_ITEMS];
  81. WM_HWIN hwin_wifi;
  82. /*********************************************************************
  83. *
  84. *       Static data
  85. *
  86. **********************************************************************
  87. */
  88. // USER START (Optionally insert additional static data)
  89. // USER END
  90. /*********************************************************************
  91. *
  92. *      
  93. */
  94. // struct message_focus_listbox* creat_struct_message_focus_listbox(uint8_t len)  
  95. // {  
  96. //     struct message_focus_listbox *message_focus_listbox = (struct message_focus_listbox *)malloc (sizeof (struct message_focus_listbox) * len);
  97. //     return message_focus_listbox;
  98. // }  
  99. /*********************************************************************
  100. *
  101. *       Static data
  102. *
  103. **********************************************************************
  104. */
  105. // USER START (Optionally insert additional static data)
  106. // USER END
  107. /*********************************************************************
  108. *
  109. *       _aDialogCreate
  110. */
  111. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  112.   { FRAMEWIN_CreateIndirect,  "Framewin",  ID_FRAMEWIN_0,  0, 0,  128, 64, 0, 0x64, 0 },
  113.   { LISTBOX_CreateIndirect,   "Listbox",   ID_LISTBOX_0,   0, 0,  118, 16, 0, 0x0,  0 },
  114.   { LISTBOX_CreateIndirect,   "Listbox",   ID_LISTBOX_1,   0, 17, 118, 16, 0, 0x0,  0 },
  115.   { SCROLLBAR_CreateIndirect, "Scrollbar", ID_SCROLLBAR_0, 0, 37, 118, 8, 0, 0x0,  0 },
  116.   // USER START (Optionally insert additional widgets)
  117.   // USER END
  118. };
  119. /*********************************************************************
  120. *
  121. *       Static code
  122. *
  123. **********************************************************************
  124. */
  125. // USER START (Optionally insert additional static code)
  126. // USER END
  127. /*********************************************************************
  128. *
  129. *       _cbDialog
  130. */
  131. static void _cbDialog(WM_MESSAGE * pMsg)
  132. {
  133.     WM_HWIN hItem;
  134.     int     NCode;
  135.     int     Id;
  136.     static int  last_id;
  137.     //
  138.     static int  current_operated_listbox;
  139.         static int  current_index_item_vscroll = 1;                // current_index_item_vscroll
  140.     /* user for hscroll*/
  141.     static int  current_selected_item_hscroll_total_steps;     // current_selected_item_hscroll_total_steps
  142.     static int  current_selected_item_hscroll_real_time_steps;
  143.     static int  last_selected_item_hscroll_real_time_steps;
  144.     char   buf[20];
  145.     // USER START (Optionally insert additional variables)
  146.     // USER END
  147.     switch (pMsg->MsgId)
  148.     {
  149.         case WM_INIT_DIALOG:
  150.             // Initialization of 'ID_TIMER_HSCROLL'
  151.             WM_CreateTimer(WM_GetClientWindow(pMsg->hWin), ID_TIMER_HSCROLL, 1000, 0);
  152.             WM_CreateTimer(WM_GetClientWindow(pMsg->hWin), ID_TIMER_ADD_WIFIAP, 500, 0);
  153.             //
  154.             // Initialization of 'Framewin'
  155.             //
  156.             hItem = pMsg->hWin;
  157.             FRAMEWIN_SetText(hItem, "Wi-Fi");
  158.             FRAMEWIN_SetFont(hItem, GUI_FONT_10_ASCII);
  159.             FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
  160.             //
  161.             // Initialization of 'Listbox'
  162.             //
  163.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_0);
  164.             LISTBOX_SetFont(hItem,GUI_FONT_16B_ASCII);
  165.             LISTBOX_AddString(hItem, "Item01234567890123456789");
  166.             //
  167.             // Initialization of 'Listbox'
  168.             //
  169.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_1);
  170.             LISTBOX_SetFont(hItem,GUI_FONT_16B_ASCII);
  171.             LISTBOX_AddString(hItem, "Item01234567890123456789");
  172.             
  173.             //
  174.             // Initialization of 'Scrollbar'
  175.             //
  176.             //hItem = WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0);
  177.             // USER START (Optionally insert additional code for further widget initialization)
  178.             // USER END
  179.             break;
  180.         case WM_NOTIFY_PARENT:
  181.             Id    = WM_GetId(pMsg->hWinSrc);
  182.             NCode = pMsg->Data.v;
  183.             switch(Id)
  184.             {
  185.                 case ID_LISTBOX_0: // Notifications sent by 'Listbox'
  186.                 switch(NCode)
  187.                 {
  188.                     case WM_NOTIFICATION_CLICKED:
  189.                         // USER START (Optionally insert code for reacting on notification message)
  190.                         // USER END
  191.                         break;
  192.                     case WM_NOTIFICATION_RELEASED:
  193.                         // USER START (Optionally insert code for reacting on notification message)
  194.                         // USER END
  195.                         break;
  196.                     case WM_NOTIFICATION_SEL_CHANGED:
  197.                         // USER START (Optionally insert code for reacting on notification message)
  198.                         // USER END
  199.                         break;
  200.                         // USER START (Optionally insert additional code for further notification handling)
  201.                         // USER END
  202.                 }
  203.                 break;
  204.                 // USER START (Optionally insert additional code for further Ids)
  205.                 // USER END
  206.                 case ID_LISTBOX_1: // Notifications sent by 'Listbox'
  207.                 switch(NCode)
  208.                 {
  209.                     case WM_NOTIFICATION_CLICKED:
  210.                         // USER START (Optionally insert code for reacting on notification message)
  211.                         // USER END
  212.                         break;
  213.                     case WM_NOTIFICATION_RELEASED:
  214.                         // USER START (Optionally insert code for reacting on notification message)
  215.                         // USER END
  216.                         break;
  217.                     case WM_NOTIFICATION_SEL_CHANGED:
  218.                         // USER START (Optionally insert code for reacting on notification message)
  219.                         // USER END
  220.                         break;
  221.                         // USER START (Optionally insert additional code for further notification handling)
  222.                         // USER END
  223.                 }
  224.                 break;
  225.                 // USER START (Optionally insert additional code for further Ids)
  226.                 // USER END
  227.                 case ID_SCROLLBAR_0: // Notifications sent by 'Listbox'
  228.                 switch(NCode)
  229.                 {
  230.                     case WM_NOTIFICATION_CLICKED:
  231.                         // USER START (Optionally insert code for reacting on notification message)
  232.                         // USER END
  233.                         break;
  234.                     case WM_NOTIFICATION_RELEASED:
  235.                         // USER START (Optionally insert code for reacting on notification message)
  236.                         // USER END        
  237.                         break;
  238.                     case WM_NOTIFICATION_SCROLLBAR_ADDED:
  239.                         // USER START (Optionally insert code for reacting on notification message)
  240.                         // USER END
  241.                         break;
  242.                     case WM_NOTIFICATION_VALUE_CHANGED:
  243.                         // USER START (Optionally insert code for reacting on notification message)
  244.                         // USER END
  245.                         break;
  246.                         // USER START (Optionally insert additional code for further notification handling)
  247.                         // USER END
  248.                 }
  249.                 break;
  250.             }
  251.         break;
  252.         // USER START (Optionally insert additional message handling)
  253.         // USER END
  254.         case WM_KEY:
  255.             Id = ((WM_KEY_INFO*)(pMsg->Data.p))->Key;
  256.             switch(Id)
  257.             {
  258.                 case GUI_KEY_ENTER: // Notifications sent by 'GUI_KEY_ENTER'
  259.                     //current_selected_item =  LISTBOX_GetSel(WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_0)) + 1;
  260.                     printf("GUI_KEY_ENTER\\r\\n");
  261.                     break;
  262.                 // USER START (Optionally insert additional code for further Ids)
  263.                 // USER END
  264.             }
  265.         break;
  266.         // USER START (Optionally insert additional message handling)
  267.         // USER END
  268.         case WM_UP_FOCUS:
  269.             // USER START (Optionally insert additional code for further Ids)
  270.             // USER END
  271.             // read current focus listbox
  272.             Id = WM_GetId(WM_GetFocussedWindow());
  273.             if(Id == ID_LISTBOX_1)
  274.             {
  275.                 printf("focus listbox ID_LISTBOX_0\\r\\n");
  276.                 hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_0);
  277.                 WM_SetFocus(hItem);
  278.             }
  279.             current_index_item_vscroll--;
  280.             printf("current_index_item_vscroll = %d",current_index_item_vscroll);
  281.             if(current_index_item_vscroll == 0)
  282.             {
  283.                 current_index_item_vscroll = 20;
  284.             }
  285.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_1);
  286.             LISTBOX_AddString(hItem, (const char*)(p_message_display_wifi_ap->name));
  287.             p_message_display_wifi_ap = &message_display_wifi_ap[current_index_item_vscroll];
  288.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_0);
  289.             LISTBOX_AddString(hItem, (const char*)(p_message_display_wifi_ap->name));
  290.         break;
  291.         // USER START (Optionally insert additional message handling)
  292.         // USER END
  293.         case WM_DOWN_FOCUS:
  294.             // USER START (Optionally insert additional code for further Ids)
  295.             // USER END
  296.             // read current focus listbox
  297.             Id = WM_GetId(WM_GetFocussedWindow());
  298.             if(Id == ID_LISTBOX_0)
  299.             {
  300.                 printf("focus listbox ID_LISTBOX_1\\r\\n");
  301.                 hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_1);
  302.                 WM_SetFocus(hItem);
  303.             }
  304.             current_index_item_vscroll++;
  305.             printf("current_index_item_vscroll = %d",current_index_item_vscroll);
  306.             if(current_index_item_vscroll == 21)
  307.             {
  308.                 current_index_item_vscroll = 1;
  309.             }
  310.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_0);
  311.             LISTBOX_AddString(hItem, (const char*)(p_message_display_wifi_ap->name));
  312.             p_message_display_wifi_ap = &message_display_wifi_ap[current_index_item_vscroll];
  313.             hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTBOX_1);
  314.             LISTBOX_AddString(hItem, (const char*)(p_message_display_wifi_ap->name));
  315.         break;
  316.         // USER START (Optionally insert additional message handling)
  317.         // USER END
  318.         case WM_TIMER:
  319.             Id = WM_GetTimerId(pMsg->Data.v);
  320.             switch (Id)
  321.             {
  322.                 case ID_TIMER_HSCROLL:
  323.                     hItem = WM_GetFocussedWindow();
  324.                     Id = WM_GetId(hItem);
  325.                     LISTBOX_SetAutoScrollH(hItem,1);
  326.                     if(last_id != Id)
  327.                     {
  328.                         LISTBOX_SetScrollStepH(hItem,1000);
  329.                         GUI_SendKeyMsg(GUI_KEY_RIGHT, 1);
  330.                         current_selected_item_hscroll_total_steps =  WM_GetScrollPosH(WM_GetDialogItem(pMsg->hWin, Id));
  331.                         LISTBOX_SetScrollStepH(hItem,1);
  332.                         SCROLLBAR_SetNumItems(WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0),current_selected_item_hscroll_total_steps + 10);
  333.                         printf("current_selected_item_hscroll_total_steps =%d\\r\\n", current_selected_item_hscroll_total_steps + 10);
  334.                         last_id = Id;
  335.                     }
  336.                     LISTBOX_SetAutoScrollH(hItem,0);
  337.                     if(dir_scroll)
  338.                     {
  339.                         SCROLLBAR_Inc(WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0));
  340.                         GUI_SendKeyMsg(GUI_KEY_RIGHT, 1);
  341.                     }else{
  342.                         SCROLLBAR_Dec(WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0));
  343.                         GUI_SendKeyMsg(GUI_KEY_LEFT, 1);
  344.                     }
  345.                     current_selected_item_hscroll_real_time_steps = WM_GetScrollPosH(WM_GetDialogItem(pMsg->hWin, Id));
  346.                     //printf("current_selected_item_hscroll_real_time_steps =%d\\r\\n", current_selected_item_hscroll_real_time_steps);
  347.                     if(last_selected_item_hscroll_real_time_steps == current_selected_item_hscroll_real_time_steps)
  348.                     {
  349.                         //dir_scroll = !dir_scroll;
  350.                         //printf("current_hscroll_real_time_steps = %d\\r\\n",current_hscroll_real_time_steps);
  351.                         WM_SetScrollPosH(WM_GetDialogItem(pMsg->hWin, Id),0);
  352.                         SCROLLBAR_AddValue(WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0),-1000);
  353.                     }
  354.                     else{
  355.                         last_selected_item_hscroll_real_time_steps = current_selected_item_hscroll_real_time_steps;
  356.                     }
  357.                     sprintf(buf, "Wi-Fi %d/%d",current_index_item_vscroll,TOTAL_ITEMS);
  358.                     FRAMEWIN_SetText(pMsg->hWin, buf);
  359.                     printf("current_index_item_vscroll = %d\\r\\n",current_index_item_vscroll);
  360.                     WM_RestartTimer(pMsg->Data.v, 1000);
  361.                     break;
  362.                 case ID_TIMER_ADD_WIFIAP:                  
  363.                     WM_RestartTimer(pMsg->Data.v, 500);
  364.                     break;
  365.             }
  366.             break;
  367.         // USER START (Optionally insert additional message handling)
  368.         // USER END
  369.         default:
  370.             WM_DefaultProc(pMsg);
  371.         break;
  372.     }
  373. }
  374. /*********************************************************************
  375. *
  376. *       Public code
  377. *
  378. **********************************************************************
  379. */
  380. /*********************************************************************
  381. *
  382. *       CreateFramewin
  383. */
  384. void CreateFramewin(void);
  385. void CreateFramewin(void) {
  386.     hwin_wifi = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, WM_HBKWIN, 0, 0);
  387. }
  388. // USER START (Optionally insert additional public code)
  389. // USER END
  390. void MainTask(void)
  391. {
  392.     // message of current focus listbox len = 20
  393.     //p_message_focus_listbox = creat_struct_message_focus_listbox(20);
  394.     /* emwin init */
  395.     GUI_Init();
  396.     /* create wm */
  397.     CreateFramewin();
  398.     WM_SetCallback(WM_HBKWIN, _cbDialog);
  399.     //WM_SendMessageNoPara(WM_HBKWIN,WM_INIT_DIALOG);
  400.     // Open Multiple Buffering
  401.     //WM_MULTIBUF_Enable(1);
  402.    
  403.     /* Use memory devices for all windows */
  404.     //WM_MOTION_Enable(1);
  405.     //WM_MOTION_SetDefaultPeriod(1000);
  406.     WM_SetCreateFlags(WM_CF_MEMDEV);
  407.     WM_EnableMemdev(hwin_wifi);  
  408.    
  409.     while(1)
  410.     {
  411.         GUI_Delay(10);
  412.         //printf("MainTask\\r\\n");
  413.     }
  414. }
  415. /*************************** End of file ****************************/
复制代码
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117635
QQ
发表于 2017-8-11 10:34:36 | 显示全部楼层
我现在手头没有OLED模块了,在显示屏上面测试了下,也没问题,你该有其它的控件试试,看看是否正常。
QQ截图20170811103051.png
回复

使用道具 举报

1

主题

4

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2017-8-11 10:47:48 | 显示全部楼层

回 eric2013 的帖子

eric2013:我现在手头没有OLED模块了,在显示屏上面测试了下,也没问题,你该有其它的控件试试,看看是否正常。

(2017-08-11 10:34)
嗯嗯好, 我模拟的也没有问题的,就是直接跑到硬件端就不行了
硬件端就只能显示一行的效果,把聚焦只是到哪里相应的就会有显示的,没有聚焦的没有显示
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117635
QQ
发表于 2017-8-11 10:49:57 | 显示全部楼层

回 tnthuahua1 的帖子

tnthuahua1:嗯嗯好, 我模拟的也没有问题的,就是直接跑到微处理器里面就不行了 (2017-08-11 10:47) 
我这个是在开发板显示屏上测试的,没问题。
回复

使用道具 举报

1

主题

4

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2017-8-11 11:15:50 | 显示全部楼层

回 eric2013 的帖子

eric2013:我这个是在开发板显示屏上测试的,没问题。 (2017-08-11 10:49)
创建两个button没问题可以显示,两个text也可以显示,两个edit貌似是显示不全,只显示了一般我刚刚接触emwin几天可能有些设置(edit)不是很对

edit

edit
微信图片_20170811111328.jpg
微信图片_20170811111331.jpg
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117635
QQ
发表于 2017-8-12 01:44:48 | 显示全部楼层

回 tnthuahua1 的帖子

tnthuahua1:创建两个button没问题可以显示,两个text也可以显示,两个edit貌似是显示不全,只显示了一般我刚刚接触emwin几天可能有些设置(edit)不是很对

 (2017-08-11 11:15) 
尝试找下底层接口函数是否可能出问题,不行的话,就用这种折中的方法显示吧。
回复

使用道具 举报

1

主题

4

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2017-8-12 17:16:14 | 显示全部楼层

回 eric2013 的帖子

eric2013:尝试找下底层接口函数是否可能出问题,不行的话,就用这种折中的方法显示吧。 (2017-08-12 01:44) 
好的,已经崩溃了
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-8-19 17:27 , Processed in 0.057379 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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