displaying the variable on the screen

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

    • Andrzej wrote:

      How to display the variable value on the screen?
      Hello.

      If you need to display some variable with constant refreshing period (for example 200 ms) you can use Timer for it.
      Here is a small example that explains the principle:

      C Source Code

      1. WM_HWIN hLabel;
      2. static void cbWindow(WM_MESSAGE * pMsg) {
      3. char* str = getValue(); // some getter, that gets stringified value to display
      4. switch (pMsg->MsgId) {
      5. case WM_TIMER:
      6. WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
      7. TEXT_SetText(hLabel, str); // shows the value
      8. break;
      9. default:
      10. WM_DefaultProc(pMsg);
      11. break;
      12. }
      13. }
      14. WM_HWIN createWindow() {
      15. WM_HWIN hWindow = WINDOW_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, 0, 0, cbWindow);
      16. hLabel = TEXT_CreateEx(10, 10, 100, 30, hWindow, WM_CF_SHOW, 0, 0, NULL);
      17. WM_CreateTimer(hWindow, 0, 0, 0); // create timer for periodical value show
      18. return hWindow;
      19. }
      Display All
      Best regards,
      Volodymyr.

      The post was edited 1 time, last by volodymyr ().

    • Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.
    • /*
      * myrolster.c
      *
      * Created on: 04.02.2019
      * Author: P
      */


      #include "stm32746g_discovery.h"
      #include "stm32746g_discovery_lcd.h"
      #include "stm32746g_discovery_sdram.h"
      #include "stm32746g_discovery_ts.h"


      #include "GUI.h"
      #include "DIALOG.h"
      #include "WM.h"
      #include "BUTTON.h"
      #include "EDIT.h"


      #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
      #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
      #define ID_BUTTON_2 (GUI_ID_USER + 0x03)
      #define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
      #define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
      #define ID_TEXT_0 (GUI_ID_USER + 0xA0)
      #define ID_TEXT_1 (GUI_ID_USER + 0xA1)
      #define ID_TEXT_2 (GUI_ID_USER + 0xA2)
      #define ID_TEXT_3 (GUI_ID_USER + 0xA3)


      #define WORK 600


      extern int posters;
      extern int poster;
      extern int showing;


      void Stop(void);
      void Up(void);
      void Down(void);
      void Working(void);


      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
      0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
      440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
      ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
      "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
      SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
      170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
      ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
      TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
      40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
      ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      "poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, };


      static void _cbDialog(WM_MESSAGE * pMsg) {
      WM_HWIN hItem;
      WM_HWIN hEdit;
      int NCode;
      int Id;
      static int isButton_0 = 1;


      switch (pMsg->MsgId) {
      case WM_INIT_DIALOG:


      hItem = pMsg->hWin;
      WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
      BUTTON_SetText(hItem, "SETTING");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
      BUTTON_SetText(hItem, "UP");
      BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
      BUTTON_SetText(hItem, "DOWN");
      BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      hEdit = SPINBOX_GetEditHandle(hItem);
      EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
      EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      hEdit = SPINBOX_GetEditHandle(hItem);
      EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
      EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      SPINBOX_SetStep(hItem, 10);
      SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "POSTERS");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "SHOW TIME");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "POSTER");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_D80);
      TEXT_SetTextColor(hItem, GUI_RED);


      break;


      case WM_NOTIFY_PARENT:
      Id = WM_GetId(pMsg->hWinSrc);
      NCode = pMsg->Data.v;
      switch (Id) {
      case ID_BUTTON_0:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      if (isButton_0) {
      isButton_0 = 0;
      BUTTON_SetText(hItem, "SCROLLING");
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetTextColor(hItem, 0, GUI_RED);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      WM_DisableWindow(hItem);
      } else {
      isButton_0 = 1;
      BUTTON_SetText(hItem, "SETTING");
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      WM_EnableWindow(hItem);
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      if (!isButton_0) {
      Working();
      }
      break;
      }
      break;
      case ID_BUTTON_1:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      if (isButton_0) {
      Up();
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      Stop();
      break;
      }
      break;
      case ID_BUTTON_2:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      if (isButton_0) {
      Down();
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      Stop();
      break;
      }
      break;
      case ID_SPINBOX_0:
      switch (NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
      posters = SPINBOX_GetValue(pMsg->hWinSrc);
      break;
      }
      break;
      case ID_SPINBOX_1:
      switch (NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
      showing = SPINBOX_GetValue(pMsg->hWinSrc);
      break;
      }
      break;
      }
      break;
      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }


      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;
      }


      void MainTask(void);


      void MainTask(void) {
      GUI_Clear();
      CreateWindow();
      }

      The post was edited 1 time, last by Andrzej: /* * myrolster.c * * Created on: 04.02.2019 * Author: P */ #include "stm32746g_discovery.h" #include "stm32746g_discovery_lcd.h" #include "stm32746g_discovery_sdram.h" #include "stm32746g_discovery_ts.h" #include "GUI.h" #include "DIALOG.h" #include "WM.h" #include "BUTTON.h" #include "EDIT.h" #define ID_WINDOW_0 (GUI_ID_USER + 0x00) #define ID_BUTTON_0 (GUI_ID_USER + 0x01) #define ID_BUTTON_1 (GUI_ID_USER + 0x02) #define ID_BUTTON_2 (GUI_ID_USER + 0x03) #define ID_SPINBOX_0 (GUI_ID_USER + 0x08) #define ID_SPINBOX_1 (GUI_ID_USER + 0x09) #define ID_TEXT_0 (GUI_ID_USER + 0xA0) #define ID_TEXT_1 (GUI_ID_USER + 0xA1) #define ID_TEXT_2 (GUI_ID_USER + 0xA2) #define ID_TEXT_3 (GUI_ID_USER + 0xA3) #define WORK 600 extern int posters; extern int poster; extern int showing; void Stop(void); void Up(void); void Down(void); void Working(void); static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = { { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10, 440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up", ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100, 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time", ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter", ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, }; static void _cbDialog(WM_MESSAGE * pMsg) { WM_HWIN hItem; WM_HWIN hEdit; int NCode; int Id; static int isButton_0 = 1; switch (pMsg->MsgId) { case WM_INIT_DIALOG: hItem = pMsg->hWin; WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000)); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII); BUTTON_SetText(hItem, "SETTING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII); BUTTON_SetText(hItem, "UP"); BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII); BUTTON_SetText(hItem, "DOWN"); BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); hEdit = SPINBOX_GetEditHandle(hItem); EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0); EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER); SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER); SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII); SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); hEdit = SPINBOX_GetEditHandle(hItem); EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0); EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER); SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER); SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII); SPINBOX_SetStep(hItem, 10); SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "POSTERS"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "SHOW TIME"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_24B_ASCII); TEXT_SetTextColor(hItem, GUI_WHITE); TEXT_SetText(hItem, "POSTER"); hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3); TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT); TEXT_SetFont(hItem, GUI_FONT_D80); TEXT_SetTextColor(hItem, GUI_RED); break; case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch (Id) { case ID_BUTTON_0: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); if (isButton_0) { isButton_0 = 0; BUTTON_SetText(hItem, "SCROLLING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetTextColor(hItem, 0, GUI_RED); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); WM_DisableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); WM_DisableWindow(hItem); } else { isButton_0 = 1; BUTTON_SetText(hItem, "SETTING"); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetTextColor(hItem, 0, GUI_BLACK); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0); WM_EnableWindow(hItem); hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1); WM_EnableWindow(hItem); } break; case WM_NOTIFICATION_RELEASED: if (!isButton_0) { Working(); } break; } break; case ID_BUTTON_1: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1); if (isButton_0) { Up(); } break; case WM_NOTIFICATION_RELEASED: Stop(); break; } break; case ID_BUTTON_2: switch (NCode) { case WM_NOTIFICATION_CLICKED: hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2); if (isButton_0) { Down(); } break; case WM_NOTIFICATION_RELEASED: Stop(); break; } break; case ID_SPINBOX_0: switch (NCode) { case WM_NOTIFICATION_VALUE_CHANGED: posters = SPINBOX_GetValue(pMsg->hWinSrc); break; } break; case ID_SPINBOX_1: switch (NCode) { case WM_NOTIFICATION_VALUE_CHANGED: showing = SPINBOX_GetValue(pMsg->hWinSrc); break; } break; } break; default: WM_DefaultProc(pMsg); break; } } 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; } void MainTask(void); void MainTask(void) { GUI_Clear(); CreateWindow(); } ().

    • Andrzej wrote:

      Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.
      I modified your code to have to compile it. I replaced your external int poster to function int poster(), that returns incremental int.
      Also I have removed all your dependencies which do not allow compile this code, added at first GUI_Init() (it is always required) and added infinite loop with GUI_Delay().

      The core point is adding to the callback the reacting to message WM_TIMER and also start Timer with function WM_CreateTimer(hWin, 0, 0, 0);

      Hope it is clear and helpful:


      C Source Code

      1. /*
      2. * myrolster.c
      3. *
      4. * Created on: 04.02.2019
      5. * Author: P
      6. */
      7. #include "GUI.h"
      8. #include "DIALOG.h"
      9. #include "WM.h"
      10. #include "BUTTON.h"
      11. #include "EDIT.h"
      12. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      13. #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
      14. #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
      15. #define ID_BUTTON_2 (GUI_ID_USER + 0x03)
      16. #define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
      17. #define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
      18. #define ID_TEXT_0 (GUI_ID_USER + 0xA0)
      19. #define ID_TEXT_1 (GUI_ID_USER + 0xA1)
      20. #define ID_TEXT_2 (GUI_ID_USER + 0xA2)
      21. #define ID_TEXT_3 (GUI_ID_USER + 0xA3)
      22. #define WORK 600
      23. int posters;
      24. int getPoster() {
      25. static int poster;
      26. return poster++;
      27. };
      28. int showing;
      29. void Stop(void) {};
      30. void Up(void) {};
      31. void Down(void) {};
      32. void Working(void) {};
      33. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      34. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
      35. 0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
      36. 440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
      37. ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
      38. "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
      39. SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
      40. 170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
      41. ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      42. "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
      43. TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
      44. 40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
      45. ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      46. "poster", ID_TEXT_3, 170, 75, 100, 100, 0, 0x0, 0 }, };
      47. static void _cbDialog(WM_MESSAGE * pMsg) {
      48. WM_HWIN hItem;
      49. WM_HWIN hEdit;
      50. int NCode;
      51. int Id;
      52. static int isButton_0 = 1;
      53. switch (pMsg->MsgId) {
      54. case WM_INIT_DIALOG:
      55. hItem = pMsg->hWin;
      56. WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));
      57. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      58. BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
      59. BUTTON_SetText(hItem, "SETTING");
      60. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      61. BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
      62. BUTTON_SetText(hItem, "UP");
      63. BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
      64. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      65. BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
      66. BUTTON_SetText(hItem, "DOWN");
      67. BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);
      68. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      69. hEdit = SPINBOX_GetEditHandle(hItem);
      70. EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
      71. EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      72. SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      73. SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      74. SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
      75. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      76. hEdit = SPINBOX_GetEditHandle(hItem);
      77. EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
      78. EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      79. SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      80. SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      81. SPINBOX_SetStep(hItem, 10);
      82. SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);
      83. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      84. TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      85. TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      86. TEXT_SetTextColor(hItem, GUI_WHITE);
      87. TEXT_SetText(hItem, "POSTERS");
      88. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
      89. TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      90. TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      91. TEXT_SetTextColor(hItem, GUI_WHITE);
      92. TEXT_SetText(hItem, "SHOW TIME");
      93. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
      94. TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      95. TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      96. TEXT_SetTextColor(hItem, GUI_WHITE);
      97. TEXT_SetText(hItem, "POSTER");
      98. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
      99. TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      100. TEXT_SetFont(hItem, GUI_FONT_D32);
      101. TEXT_SetTextColor(hItem, GUI_RED);
      102. break;
      103. case WM_TIMER:
      104. WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
      105. char str[20];
      106. sprintf(str, "%d", getPoster());
      107. TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_3), str); // shows the value
      108. break;
      109. case WM_NOTIFY_PARENT:
      110. Id = WM_GetId(pMsg->hWinSrc);
      111. NCode = pMsg->Data.v;
      112. switch (Id) {
      113. case ID_BUTTON_0:
      114. switch (NCode) {
      115. case WM_NOTIFICATION_CLICKED:
      116. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      117. if (isButton_0) {
      118. isButton_0 = 0;
      119. BUTTON_SetText(hItem, "SCROLLING");
      120. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      121. BUTTON_SetTextColor(hItem, 0, GUI_RED);
      122. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      123. WM_DisableWindow(hItem);
      124. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      125. WM_DisableWindow(hItem);
      126. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      127. WM_DisableWindow(hItem);
      128. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      129. WM_DisableWindow(hItem);
      130. }
      131. else {
      132. isButton_0 = 1;
      133. BUTTON_SetText(hItem, "SETTING");
      134. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      135. BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
      136. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      137. WM_EnableWindow(hItem);
      138. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      139. WM_EnableWindow(hItem);
      140. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      141. WM_EnableWindow(hItem);
      142. hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      143. WM_EnableWindow(hItem);
      144. }
      145. break;
      146. case WM_NOTIFICATION_RELEASED:
      147. if (!isButton_0) {
      148. Working();
      149. }
      150. break;
      151. }
      152. break;
      153. case ID_BUTTON_1:
      154. switch (NCode) {
      155. case WM_NOTIFICATION_CLICKED:
      156. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      157. if (isButton_0) {
      158. Up();
      159. }
      160. break;
      161. case WM_NOTIFICATION_RELEASED:
      162. Stop();
      163. break;
      164. }
      165. break;
      166. case ID_BUTTON_2:
      167. switch (NCode) {
      168. case WM_NOTIFICATION_CLICKED:
      169. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      170. if (isButton_0) {
      171. Down();
      172. }
      173. break;
      174. case WM_NOTIFICATION_RELEASED:
      175. Stop();
      176. break;
      177. }
      178. break;
      179. case ID_SPINBOX_0:
      180. switch (NCode) {
      181. case WM_NOTIFICATION_VALUE_CHANGED:
      182. posters = SPINBOX_GetValue(pMsg->hWinSrc);
      183. break;
      184. }
      185. break;
      186. case ID_SPINBOX_1:
      187. switch (NCode) {
      188. case WM_NOTIFICATION_VALUE_CHANGED:
      189. showing = SPINBOX_GetValue(pMsg->hWinSrc);
      190. break;
      191. }
      192. break;
      193. }
      194. break;
      195. default:
      196. WM_DefaultProc(pMsg);
      197. break;
      198. }
      199. }
      200. WM_HWIN CreateWindow(void);
      201. WM_HWIN CreateWindow(void) {
      202. WM_HWIN hWin;
      203. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate),
      204. _cbDialog, WM_HBKWIN, 0, 0);
      205. WM_CreateTimer(hWin, 0, 0, 0);
      206. return hWin;
      207. }
      208. void MainTask(void);
      209. void MainTask(void) {
      210. GUI_Init();
      211. WM_SetBkWindowColor(GUI_GRAY);
      212. CreateWindow();
      213. while (1) {
      214. GUI_Delay(100);
      215. };
      216. }
      Display All

      By the way, it is bad practice to work with external variables, much better is to make for all of them some getters (like my function poster(), which should be defined in the c-file, that contains and exports such variables) and publish them via header-file. This principle called encapsulation. You cannot change this variable, only read. And you can control this reading because you have a function instead direct access.

      But if you need to change these variables, you write "setters" like:

      C Source Code

      1. void setPoster(int value) {
      2. poster = value;
      3. }
      and then you also have full control in changing of such variables.
      Best regards,
      Volodymyr.

      The post was edited 5 times, last by volodymyr ().

    • volodymyr wrote:

      Andrzej wrote:

      How to display the variable value on the screen?
      Hello.
      If you need to display some variable with constant refreshing period (for example 200 ms) you can use Timer for it.
      Here is a small example that explains the principle:

      C Source Code

      1. WM_HWIN hLabel;
      2. static void cbWindow(WM_MESSAGE * pMsg) {
      3. char* str = getValue(); // some getter, that gets stringified value to display
      4. switch (pMsg->MsgId) {
      5. case WM_TIMER:
      6. WM_RestartTimer(pMsg->Data.v, 200); // restart timer to 200ms for next timer message
      7. TEXT_SetText(hLabel, str); // shows the value
      8. break;
      9. default:
      10. WM_DefaultProc(pMsg);
      11. break;
      12. }
      13. }
      14. WM_HWIN createWindow() {
      15. WM_HWIN hWindow = WINDOW_CreateEx(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, 0, 0, cbWindow);
      16. hLabel = TEXT_CreateEx(10, 10, 100, 30, hWindow, WM_CF_SHOW, 0, 0, NULL);
      17. WM_CreateTimer(hWindow, 0, 0, 0); // create timer for periodical value show
      18. return hWindow;
      19. }
      Display All

      Andrzej wrote:

      Thank you. However, I don't know how to integrate it into my program. I have the external variable "poster", they have to be numbers 1 to 6. They change in another part of the program. I want to display the variable value on an ongoing basis. I have prepared ID_TEXT_3 but I do not know how to display it to reflect the changes.

      Andrzej wrote:

      /*
      * myrolster.c
      *
      * Created on: 04.02.2019
      * Author: P
      */


      #include "stm32746g_discovery.h"
      #include "stm32746g_discovery_lcd.h"
      #include "stm32746g_discovery_sdram.h"
      #include "stm32746g_discovery_ts.h"


      #include "GUI.h"
      #include "DIALOG.h"
      #include "WM.h"
      #include "BUTTON.h"
      #include "EDIT.h"


      #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      #define ID_BUTTON_0 (GUI_ID_USER + 0x01)
      #define ID_BUTTON_1 (GUI_ID_USER + 0x02)
      #define ID_BUTTON_2 (GUI_ID_USER + 0x03)
      #define ID_SPINBOX_0 (GUI_ID_USER + 0x08)
      #define ID_SPINBOX_1 (GUI_ID_USER + 0x09)
      #define ID_TEXT_0 (GUI_ID_USER + 0xA0)
      #define ID_TEXT_1 (GUI_ID_USER + 0xA1)
      #define ID_TEXT_2 (GUI_ID_USER + 0xA2)
      #define ID_TEXT_3 (GUI_ID_USER + 0xA3)


      #define WORK 600


      extern int posters;
      extern int poster;
      extern int showing;


      void Stop(void);
      void Up(void);
      void Down(void);
      void Working(void);


      static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0,
      0 }, { BUTTON_CreateIndirect, "scrollset", ID_BUTTON_0, 20, 10,
      440, 60, 0, 0x0, 0 }, { BUTTON_CreateIndirect, "up",
      ID_BUTTON_1, 20, 100, 170, 50, 0, 0x0, 0 }, { BUTTON_CreateIndirect,
      "down", ID_BUTTON_2, 20, 190, 170, 50, 0, 0x0, 0 }, {
      SPINBOX_CreateIndirect, "postershow", ID_SPINBOX_0, 290, 100,
      170, 50, 0, 0x0, 0 }, { SPINBOX_CreateIndirect, "time",
      ID_SPINBOX_1, 290, 190, 170, 50, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      "signatureposters", ID_TEXT_0, 265, 140, 160, 40, 0, 0x0, 0 }, {
      TEXT_CreateIndirect, "signaturetime", ID_TEXT_1, 275, 230, 160,
      40, 0, 0x0, 0 }, { TEXT_CreateIndirect, "signatureposter",
      ID_TEXT_2, 120, 160, 160, 40, 0, 0x0, 0 }, { TEXT_CreateIndirect,
      "poster", ID_TEXT_3, 165, 75, 100, 100, 0, 0x0, 0 }, };


      static void _cbDialog(WM_MESSAGE * pMsg) {
      WM_HWIN hItem;
      WM_HWIN hEdit;
      int NCode;
      int Id;
      static int isButton_0 = 1;


      switch (pMsg->MsgId) {
      case WM_INIT_DIALOG:


      hItem = pMsg->hWin;
      WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00A00000));


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetFont(hItem, GUI_FONT_32B_ASCII);
      BUTTON_SetText(hItem, "SETTING");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      BUTTON_SetFont(hItem, GUI_FONT_24B_ASCII);
      BUTTON_SetText(hItem, "UP");
      BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      BUTTON_SetFont(hItem, GUI_FONT_20B_ASCII);
      BUTTON_SetText(hItem, "DOWN");
      BUTTON_SetTextColor(hItem, BUTTON_CI_PRESSED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      hEdit = SPINBOX_GetEditHandle(hItem);
      EDIT_SetDecMode(hEdit, 0, 1, 6, 0, 0);
      EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      hEdit = SPINBOX_GetEditHandle(hItem);
      EDIT_SetDecMode(hEdit, 0, 10, 180, 0, 0);
      EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER);
      SPINBOX_SetEdge(hItem, SPINBOX_EDGE_CENTER);
      SPINBOX_SetFont(hItem, GUI_FONT_32B_ASCII);
      SPINBOX_SetStep(hItem, 10);
      SPINBOX_SetTextColor(hItem, SPINBOX_CI_ENABLED, GUI_RED);


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "POSTERS");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_1);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "SHOW TIME");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_24B_ASCII);
      TEXT_SetTextColor(hItem, GUI_WHITE);
      TEXT_SetText(hItem, "POSTER");


      hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_3);
      TEXT_SetTextAlign(hItem, GUI_TA_VCENTER | GUI_TA_RIGHT);
      TEXT_SetFont(hItem, GUI_FONT_D80);
      TEXT_SetTextColor(hItem, GUI_RED);


      break;


      case WM_NOTIFY_PARENT:
      Id = WM_GetId(pMsg->hWinSrc);
      NCode = pMsg->Data.v;
      switch (Id) {
      case ID_BUTTON_0:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      if (isButton_0) {
      isButton_0 = 0;
      BUTTON_SetText(hItem, "SCROLLING");
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetTextColor(hItem, 0, GUI_RED);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      WM_DisableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      WM_DisableWindow(hItem);
      } else {
      isButton_0 = 1;
      BUTTON_SetText(hItem, "SETTING");
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0);
      BUTTON_SetTextColor(hItem, 0, GUI_BLACK);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_0);
      WM_EnableWindow(hItem);
      hItem = WM_GetDialogItem(pMsg->hWin, ID_SPINBOX_1);
      WM_EnableWindow(hItem);
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      if (!isButton_0) {
      Working();
      }
      break;
      }
      break;
      case ID_BUTTON_1:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_1);
      if (isButton_0) {
      Up();
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      Stop();
      break;
      }
      break;
      case ID_BUTTON_2:
      switch (NCode) {
      case WM_NOTIFICATION_CLICKED:
      hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
      if (isButton_0) {
      Down();
      }
      break;
      case WM_NOTIFICATION_RELEASED:
      Stop();
      break;
      }
      break;
      case ID_SPINBOX_0:
      switch (NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
      posters = SPINBOX_GetValue(pMsg->hWinSrc);
      break;
      }
      break;
      case ID_SPINBOX_1:
      switch (NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
      showing = SPINBOX_GetValue(pMsg->hWinSrc);
      break;
      }
      break;
      }
      break;
      default:
      WM_DefaultProc(pMsg);
      break;
      }
      }


      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;
      }


      void MainTask(void);


      void MainTask(void) {
      GUI_Clear();
      CreateWindow();
      }
      Thank you for the changes and comments on the programming style. Now I will check how it goes.