LISTVIEW_GetSel() function always returning 0 after vertical scrollbar has been moved.

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • LISTVIEW_GetSel() function always returning 0 after vertical scrollbar has been moved.

    Hi,

    I am writing an application running on a STM32 processor using the STemWin precompiled library based on emWin version 5.40.

    I am using a 'LISTVIEW' object in my application to list 100 items for the user to select from.

    I am able to select an item from the list and the index is returned correctly until the vertical scrollbar is moved, once the vertical scrollbar has been moved the LISTVIEW_GetSel() function is always returning the value 0 regardless of the selection in the 'LISTVIEW'.

    Here is a snippet of my window callback which handles this...

    C Source Code

    1. static int selected;
    2. case WM_NOTIFY_PARENT:
    3. Id = WM_GetId(pMsg->hWinSrc);
    4. NCode = pMsg->Data.v;
    5. switch(Id) {
    6. case ID_LISTVIEW_0: // Notifications sent by 'Listview'
    7. switch(NCode) {
    8. case WM_NOTIFICATION_CLICKED:
    9. WM_HideWindow(_hNumKeyboard);
    10. break;
    11. case WM_NOTIFICATION_RELEASED:
    12. break;
    13. case WM_NOTIFICATION_SEL_CHANGED:
    14. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
    15. selected = LISTVIEW_GetSel(hItem);
    16. break;
    17. }
    18. break;
    Display All


    I have tried using the auto scroll bar function and have also tried adding the scrollbar manually but both scenarios yield the same result.

    I would appreciate it if you have any suggestions as to what might be going wrong here. Hopefully I am just missing something obvious!

    Thank you in advance.

    Kind Regards,

    Pete
  • Hello Pete,

    I have tried to reproduce this but it is working on my side. I have tested with the latest version of emWin as well as with V5.40.

    Here is the code I have used for testing:

    C Source Code

    1. #include "DIALOG.h"
    2. #include <stdio.h>
    3. /*********************************************************************
    4. *
    5. * Defines
    6. *
    7. **********************************************************************
    8. */
    9. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    10. #define ID_LISTVIEW_0 (GUI_ID_USER + 0x02)
    11. /*********************************************************************
    12. *
    13. * Static data
    14. *
    15. **********************************************************************
    16. */
    17. /*********************************************************************
    18. *
    19. * _aDialogCreate
    20. */
    21. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    22. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
    23. { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 10, 10, 302, 252, 0, 0x0, 0 },
    24. };
    25. /*********************************************************************
    26. *
    27. * Static code
    28. *
    29. **********************************************************************
    30. */
    31. /*********************************************************************
    32. *
    33. * _cbDialog
    34. */
    35. static void _cbDialog(WM_MESSAGE * pMsg) {
    36. WM_HWIN hItem;
    37. int NCode;
    38. int Id;
    39. char acBuffer[64];
    40. int Sel;
    41. int i;
    42. switch (pMsg->MsgId) {
    43. case WM_INIT_DIALOG:
    44. //
    45. // Initialization of 'Listview'
    46. //
    47. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
    48. LISTVIEW_AddColumn(hItem, 100, "Col 0", GUI_TA_HCENTER | GUI_TA_VCENTER);
    49. LISTVIEW_AddColumn(hItem, 100, "Col 1", GUI_TA_HCENTER | GUI_TA_VCENTER);
    50. LISTVIEW_AddColumn(hItem, 100, "Col 2", GUI_TA_HCENTER | GUI_TA_VCENTER);
    51. for (i = 0; i < 100; i++) {
    52. LISTVIEW_AddRow(hItem, NULL);
    53. sprintf(acBuffer, "Item %i", i);
    54. LISTVIEW_SetItemText(hItem, 0, i, acBuffer);
    55. }
    56. LISTVIEW_SetAutoScrollV(hItem, 1);
    57. LISTVIEW_SetGridVis(hItem, 1);
    58. break;
    59. case WM_NOTIFY_PARENT:
    60. Id = WM_GetId(pMsg->hWinSrc);
    61. NCode = pMsg->Data.v;
    62. switch(Id) {
    63. case ID_LISTVIEW_0: // Notifications sent by 'Listview'
    64. switch(NCode) {
    65. case WM_NOTIFICATION_CLICKED:
    66. break;
    67. case WM_NOTIFICATION_RELEASED:
    68. break;
    69. case WM_NOTIFICATION_SEL_CHANGED:
    70. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
    71. Sel = LISTVIEW_GetSel(hItem);
    72. break;
    73. }
    74. break;
    75. }
    76. break;
    77. default:
    78. WM_DefaultProc(pMsg);
    79. break;
    80. }
    81. }
    82. /*********************************************************************
    83. *
    84. * Public code
    85. *
    86. **********************************************************************
    87. */
    88. /*********************************************************************
    89. *
    90. * MainTask
    91. */
    92. void MainTask(void) {
    93. GUI_Init();
    94. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    95. while (1) {
    96. GUI_Delay(100);
    97. }
    98. }
    99. /*************************** End of file ****************************/
    Display All


    For now I can't say what is going wrong on your side. Please give it a try and check if the code above runs.

    Regards
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Sven,

    Thank you for your fast response.

    I added your code to my application as a new module and when called it does indeed work correctly, so that leaves me thinking I have probably done something stupid in the module that is coursing me a problem.

    I have attached the code for the entire module, it would be much appreciated if you wouldn't mind taking a quick look to see if there is anything obviously wrong that might break the LISTVIEW_GetSel() function.

    Thanks again.

    Kind Regards,

    Pete
    Files
    • point.zip

      (2.86 kB, downloaded 248 times, last: )
  • Hi,

    I checked your application, but I couldn't find anything obvious. I modified it a little bit to be able to let in run in the simulation (deleting unknowns), but it was working. I always get the proper selection, no matter if I use the scrollbar.

    Attached is my modified version.

    Not sure if this will help, but did you tried to increase the emWin memory (most likely in GUIConf.c)?

    Regards
    Sven
    Files
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hi Sven,

    Thank you again for your fast response.

    I monitor the free GUI memory all the time and it never gets below about 2MB so I don't think there is a memory allocation issue. It is however worrying that this is happening as it suggests stack corruption or something of that nature. I will have to look into the application as a whole now see if I can see what is going wrong.

    Thank you for your time and confirming there are no known issues with the 'LISTVIEW' item at this time.

    I will continue to look into the issue here.

    Cheers,

    Pete