Overwriting GUIBuilder Window Creation Callback

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

    • Overwriting GUIBuilder Window Creation Callback

      Hello
      How Can I overwrite GUIBuilder window creation callback. I want to draw a window with gradient background color.

      I tried the following modification on GUIBuilder output, but i did not work.

      (Compiler warning is included at the bottom of code)

      C Source Code: Gradient window

      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. /*********************************************************************
      24. *
      25. * Defines
      26. *
      27. **********************************************************************
      28. */
      29. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      30. // USER START (Optionally insert additional defines)
      31. // USER END
      32. /*********************************************************************
      33. *
      34. * Static data
      35. *
      36. **********************************************************************
      37. */
      38. // USER START (Optionally insert additional static data)
      39. static void _cbWin0(WM_MESSAGE * pMsg) {
      40. GUI_RECT Rect;
      41. switch (pMsg->MsgId) {
      42. case WM_PAINT:
      43. WM_GetClientRect(&Rect);
      44. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_RED, GUI_BLUE);
      45. break;
      46. default:
      47. WM_DefaultProc(pMsg);
      48. break;
      49. }
      50. }
      51. // USER END
      52. /*********************************************************************
      53. *
      54. * _aDialogCreate
      55. */
      56. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      57. { WINDOW_CreateIndirect, "Gradient", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, _cbWin0 },
      58. // USER START (Optionally insert additional widgets)
      59. // USER END
      60. };
      61. /*********************************************************************
      62. *
      63. * Static code
      64. *
      65. **********************************************************************
      66. */
      67. // USER START (Optionally insert additional static code)
      68. // USER END
      69. /*********************************************************************
      70. *
      71. * _cbDialog
      72. */
      73. static void _cbDialog(WM_MESSAGE * pMsg) {
      74. // USER START (Optionally insert additional variables)
      75. // USER END
      76. switch (pMsg->MsgId) {
      77. // USER START (Optionally insert additional message handling)
      78. // USER END
      79. default:
      80. WM_DefaultProc(pMsg);
      81. break;
      82. }
      83. }
      84. /*********************************************************************
      85. *
      86. * Public code
      87. *
      88. **********************************************************************
      89. */
      90. /*********************************************************************
      91. *
      92. * CreateGradient
      93. */
      94. WM_HWIN CreateGradient(void);
      95. WM_HWIN CreateGradient(void) {
      96. WM_HWIN hWin;
      97. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      98. return hWin;
      99. }
      100. // USER START (Optionally insert additional public code)
      101. // USER END
      102. /*************************** End of file ****************************/
      103. //*************************************************
      104. Compiler output:
      105. ->Warinigs (1 Item)
      106. initialization makes integer from pointer without a cast [-Wint-conversion]
      107. ->Infos (1 Item)
      108. (near initialization for '_aDialogCreate[0].NumExtraBytes')
      109. **************************************************/
      Display All
      Thanks in advance
    • Hi,

      the GUI_WIDGET_CREATE_INFO structure is defined as follows:

      C Source Code

      1. struct GUI_WIDGET_CREATE_INFO_struct {
      2. GUI_WIDGET_CREATE_FUNC * pfCreateIndirect;
      3. const char * pName; // Text ... Not used on all widgets
      4. I16 Id; // ID ... should be unique in a dialog
      5. I16 x0; // x position
      6. I16 y0; // y position
      7. I16 xSize; // x size
      8. I16 ySize; // y size
      9. U16 Flags; // Widget specific create flags (opt.)
      10. I32 Para; // Widget specific parameter (opt.)
      11. U32 NumExtraBytes; // Number of extra bytes usable with <WIDGET>_SetUserData & <WIDGET>_GetUserData
      12. };
      Display All
      As last parameter you passed a pointer to a callback function, where the number of extra bytes to be allocated should be. So instead of _cbWin, you can just pass 0 as last parameter.
      The WINDOW widget in your _aDialogCreate structure is not a separate window widget, it is the dialog. So, to draw a gradient you don't need another callback, you can just copy the WM_PAINT case from _cbWin0 into the _cbDialog callback.

      Best regards,

      Florian
      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.