Invalidating a Text box

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

    • Invalidating a Text box

      Hi ,
      I have a main window which has a Text Box [hText1] and this text box has two other child text boxes [hText_c1] and [hText_c2] . Both the child text boxes display three digit numbers which keeps on changing from 0 to 999 . So I added the below code in my Freertos task as below :

      static void digit_rotate(void *pvParamaters)
      {
      int i;
      for(;;){
      for(i= 000;i<999;i++){
      GUI_Exec();
      itoa(i,str,10);
      WM_Invalidate(hText_c1);
      vTaskDelay(TIME_DELAY_SLEEP);
      }
      }
      }

      I created the text boxes using the GUI builder and the text box creation is added under WM_INIT_DIALOG as below

      hText1= WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
      TEXT_SetBkColor(hText1,GUI_OFFWHITE);
      TEXT_SetText(hText1,"");

      hText_c1= WM_GetDialogItem(pMsg->hWin, ID_TEXT_5);
      TEXT_SetFont(hText_c1, &GUI_FontTimesNewRoman250);
      TEXT_SetTextAlign(hText_c1, GUI_TA_HCENTER | GUI_TA_VCENTER);
      WM_SetCallback(hText_c1,_cbchangevalue); // Call back function for the first child window whether WM_PAINT message is proccessed.

      hText_c2= WM_GetDialogItem(pMsg->hWin, ID_TEXT_6);
      TEXT_SetFont(hText_c2, &GUI_FontTimesNewRoman250);
      TEXT_SetTextAlign(hText_c2, GUI_TA_HCENTER | GUI_TA_VCENTER);


      The callback function of the first child box to change the text box value is

      static void _cbchangevalue(WM_MESSAGE * pMsg)
      {
      int res;
      switch (pMsg->MsgId){
      case WM_PAINT:
      res = TEXT_SetText(hText_c1, str);
      PRINTF("\n Set text is %d \n",res);
      break;
      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }

      I made sure that the control is moving to the _cbchangevalue and I am getting the TEXT_SetText return value as success and failure alternatively and the first child box appears to be blank all the time.

      It will be helpful if someone explains what is actually happening here. What am I missing in my code?
    • Hi,

      why don't you simply call TEXT_SetText() from digit_rotate()?

      It is not recommended to call TEXT_SetText() from within a WM_PAINT event. In WM_PAINT event only drawing operations should be performed.
      I'm wondering if hText_c1 will display something at all. You have overwritten its callback function and in WM_PAINT you don't draw anything.
      Also, if you overwrite a callback function of a widget you have to call the widgets default callback function and not WM_DefaultProc(). The later function is only for windows created by WM_CreateWindow(). You should use TEXT_Callback().

      Try something like this:


      C Source Code

      1. #include "DIALOG.h"
      2. #include <stdio.h>
      3. /*********************************************************************
      4. *
      5. * Externals
      6. *
      7. **********************************************************************
      8. */
      9. /*********************************************************************
      10. *
      11. * Defines
      12. *
      13. **********************************************************************
      14. */
      15. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      16. #define ID_TEXT_0 (GUI_ID_USER + 0x01)
      17. #define ID_TEXT_1 (GUI_ID_USER + 0x02)
      18. #define ID_TEXT_2 (GUI_ID_USER + 0x03)
      19. /*********************************************************************
      20. *
      21. * Static data
      22. *
      23. **********************************************************************
      24. */
      25. /*********************************************************************
      26. *
      27. * _aDialogCreate
      28. */
      29. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      30. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      31. { TEXT_CreateIndirect, "Text_P", ID_TEXT_0, 50, 80, 180, 60, 0, 0x0, 0 },
      32. { TEXT_CreateIndirect, "Text_C1", ID_TEXT_1, 50, 80, 60, 60, 0, 0x0, 0 },
      33. { TEXT_CreateIndirect, "Text_C2", ID_TEXT_2, 170, 80, 60, 60, 0, 0x0, 0 },
      34. };
      35. /*********************************************************************
      36. *
      37. * Static code
      38. *
      39. **********************************************************************
      40. */
      41. /*********************************************************************
      42. *
      43. * _cbDialog
      44. */
      45. static void _cbDialog(WM_MESSAGE * pMsg) {
      46. WM_HWIN hItem;
      47. switch (pMsg->MsgId) {
      48. case WM_INIT_DIALOG:
      49. //
      50. // Initialization of 'Text_P'
      51. //
      52. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      53. TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
      54. //
      55. // Initialization of 'Text_C1'
      56. //
      57. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
      58. TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
      59. //
      60. // Initialization of 'Text_C2'
      61. //
      62. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
      63. TEXT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER);
      64. break;
      65. default:
      66. WM_DefaultProc(pMsg);
      67. break;
      68. }
      69. }
      70. /*********************************************************************
      71. *
      72. * _cbBk
      73. */
      74. static void _cbBk(WM_MESSAGE * pMsg) {
      75. switch (pMsg->MsgId) {
      76. case WM_PAINT:
      77. GUI_SetBkColor(GUI_BLACK);
      78. GUI_Clear();
      79. break;
      80. default:
      81. WM_DefaultProc(pMsg);
      82. break;
      83. }
      84. }
      85. /*********************************************************************
      86. *
      87. * Public code
      88. *
      89. **********************************************************************
      90. */
      91. /*********************************************************************
      92. *
      93. * MainTask
      94. */
      95. void MainTask(void) {
      96. WM_HWIN hDialog;
      97. WM_HWIN hText_c1;
      98. char acBuffer[8];
      99. int Value;
      100. GUI_Init();
      101. WM_SetCallback(WM_HBKWIN, _cbBk);
      102. hDialog = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      103. hText_c1 = WM_GetDialogItem(hDialog, ID_TEXT_1);
      104. Value = 0;
      105. while (1) {
      106. sprintf(acBuffer, "%i", Value++);
      107. TEXT_SetText(hText_c1, acBuffer);
      108. Value = (Value == 1000) ? 0 : Value;
      109. GUI_Delay(250);
      110. }
      111. }
      112. /*************************** End of file ****************************/
      Display All
      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.