Hide or Show dinamically a Button widget

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

    • Hide or Show dinamically a Button widget

      Hi to all,

      I hava aWindows with 5 buttons generated with GUIBuilder (I use version from ST, so GUIBuilder mandatory).

      I need to dinamically apdate caption e number of Buttons (hide or show some buttons).

      For caption, I modified the _aDialogCreate to retrive Data from a array that I fill before call CreateWindow()


      C Source Code

      1. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      2. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 240, 320, 0, 0x0, 0 },
      3. //{ BUTTON_CreateIndirect, "1", ID_BUTTON_0, 45, 7, 150, 50, 0, 0x0, 0 },
      4. //{ BUTTON_CreateIndirect, "2", ID_BUTTON_1, 45, 71, 150, 50, 0, 0x0, 0 },
      5. //{ BUTTON_CreateIndirect, "3", ID_BUTTON_2, 45, 135, 150, 50, 0, 0x0, 0 },
      6. //{ BUTTON_CreateIndirect, "4", ID_BUTTON_3, 45, 199, 150, 50, 0, 0x0, 0 },
      7. //{ BUTTON_CreateIndirect, "5", ID_BUTTON_4, 45, 263, 150, 50, 0, 0x0, 0 },
      8. // USER START (Optionally insert additional widgets)
      9. { BUTTON_CreateIndirect, (char *)stringa1, ID_BUTTON_0, 45, 7, 150, 50, 0, 0x0, 0 },
      10. { BUTTON_CreateIndirect, (char *)stringa2, ID_BUTTON_1, 45, 71, 150, 50, 0, 0x0, 0 },
      11. { BUTTON_CreateIndirect, (char *)stringa3, ID_BUTTON_2, 45, 135, 150, 50, 0, 0x0, 0 },
      12. { BUTTON_CreateIndirect, (char *)stringa4, ID_BUTTON_3, 45, 199, 150, 50, 0, 0x0, 0 },
      13. { BUTTON_CreateIndirect, (char *)stringa5, ID_BUTTON_4, 45, 263, 150, 50, 0, 0x0, 0 },
      14. // USER END
      15. };
      Display All
      But I have no idea how to hide a button or not

      I want to insert in _cbDialog - > case WM_INIT_DIALOG (as just done here), a switch-case that configure Buttons hide/show.

      How Can I do that ?
    • Hi,

      To show and hide widgets/windows you can use the routines WM_ShowWindow() and WM_HideWindow().

      ter2 wrote:

      I want to insert in _cbDialog - > case WM_INIT_DIALOG (as just done here), a switch-case that configure Buttons hide/show.

      A switch-case like in WM_NOTIFY_PARENT won't work in WM_INIT_DIALOG. WM_INIT_DIALOG is only sent once to the parent dialog, after it has been initialized. In WM_INIT_DIALOG, you can retrieve the button handles from the IDs by using WM_GetDialogItem(), e.g. WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0).

      After you have retrieved the button handle, you can e.g. hide the widget, or call any of the BUTTON_* routines to edit the widget's properties, e.g. the button text with BUTTON_SetText().

      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.
    • HI Florian,

      Thanks. I thought WM_HideWindow() was only used for windows or screen areas, not widgets.

      Switch-case work fine, in WM_INIT_DIALOG I have inserted the following code which hides buttons 1 and 5 with screen_1 and only button 1 with screen_2

      C Source Code

      1. for (i = 0; i < 5; i++) {
      2. hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0 + i);
      3. WIDGET_SetFocusable(hItem, 0);
      4. switch(State_Screen){
      5. case SCREEN_1:
      6. if((i == 4) || (i == 0)){
      7. WM_HideWindow(hItem);
      8. }
      9. case SCREEN_2:
      10. if(i == 0){
      11. WM_HideWindow(hItem);
      12. }
      13. if(i == 4){
      14. WM_ShowWindow(hItem);
      15. }
      16. break;
      17. default:
      18. break;
      19. }
      20. }
      Display All

      I have a second question: I have to insert an image that resides in FLASH in the screen created by GUIBuilder.

      The image is inserted with this string:

      Source Code

      1. { IMAGE_CreateIndirect, "Image", ID_IMAGE_0, 93, 7, 50, 50, 0, IMAGE_CF_MEMDEV, 0 },


      If I use draex outside the GUIBuilder, the image is displayed correctly

      Source Code

      1. GUI_BMP_DrawEx(GUI_ReadFromFlash, (void *)&(IMPOSTAZIONE), 90, 1);

      Thanks.
    • Hi,

      ter2 wrote:

      Thanks. I thought WM_HideWindow() was only used for windows or screen areas, not widgets.
      Widgets are windows, that means the Window Manager API routines (prefixed with WM_) also work with widgets.


      ter2 wrote:

      I have a second question: I have to insert an image that resides in FLASH in the screen created by GUIBuilder.
      You can set the external BMP image to the widget with IMAGE_SetBMPEx().

      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.