Multiple windows handling on button click event

  • I am able to create different dialog boxes but what I am trying to do is that I need to create 2 windows and when I press the button in window 1 then window 2 should be displayed and vice-versa. I went through example codes but could not find anything that does what I want. Any help would be appreciated.

  • Hi,

    Something like this (attached)?

    I create one window with a button. On button release I create a second window and delete the first. The second window has also a button. On press I create the first one again and delete the second one.

    Regards,
    Sven

  • This works fine but what I am trying to do is following:

    1. My display is 640x480 and I want to create first page (GUI_BLUE) with full display size. A button on this page, when pressed, would take me to another page (GUI_RED).
    2. Button on second page, when pressed, takes me back to the BLUE page.

    Can this be achieved by WM_SetFocus() when button is pressed?

    Since the display size is 640x480, I think I would have to create a display of XSize 640*2. I am not sure about this though.

  • I have attached my code as well as output after making some changes to your code.

    When I debug this code, I get the following result:

    1. The code starts with the display showing a small red window with the button named "Select Win2".
    2. When I press "Select Win2" button, I get a green window (fully covers the display since I have passed LCD_GetXSize() and LCD_GetYSize() as arguments) with a button named "Select Win1".
    3. When I press "Select Win1" button, I get a red window which again fully covers the display due to the above mentioned reason.
    4. The display then toggles between these red and green windows on button press.

    This is not what I want.

    I want the code to display a window with "Select Win2" button as my starting point. Then the windows should change on button press. I hope I am clear with my end result.

  • I modified the code and now it works as I want. I have commented GUI_Init() and WM_MULTIBUF_Enable(1) because I am already calling them in main.c.

    Thank you Shoenen!

    Edited 2 times, last by hrm2519 (September 10, 2021 at 1:52 PM).

  • I do it differently. Is it legal?

    tskGUI
    ...
    // Screen numbering
    //enum {W_SETTINGS, W_WPRIMCH1, W_WPRIMCH2, W_WTIME, W_MAX};
    // Current screen number. Declaring the function of creating a dialog.
    int16_t NScreen = W_SETTINGS;
    WM_HWIN (*pCreateWin[W_MAX])() =
    {
    CreateWSettings, CreateWPrimCh1, CreateWPrimCh2, CreateWTime,
    };
    WM_HWIN hCurWin = NULL;

    ...

    // Declare a callback routine on a blank screen
    WM_SetCallback(WM_GetDesktopWindowEx(0), _cbBk);
    // start GUI
    //hCurWin = CreateWSettings();
    hCurWin = pCreateWin[NScreen]();
    WM_ShowWindow(hCurWin);
    // Show the main menu
    WM_Exec();
    CleanDisplay(0xC0000000);
    // Gui background Task
    while(1)
    {
    GUI_Exec(); // Do the background work ... Update windows etc.)
    osDelay(10);
    }
    ....
    static void _cbBk(WM_MESSAGE * pMsg)
    {
    uint32_t NCode/*, Id*/;
    switch (pMsg->MsgId)
    {
    case WM_PAINT:
    break;
    case WM_NOTIFY_PARENT:
    //Id = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch (NCode)
    {
    case WM_NOTIFICATION_CHILD_DELETED:
    if(NScreen < 0) NScreen = 0;
    if(NScreen > W_MAX) NScreen = 0;
    hCurWin = pCreateWin[NScreen]();
    WM_ShowWindow(hCurWin);
    break;
    default:
    break;
    }
    break;
    default:
    WM_DefaultProc(pMsg);
    }
    }

    ......

    The screen is rendered as a dialog. Like that...

    WM_HWIN CreateWPrimCh1(void) {
    WM_HWIN hWin;

    hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    return hWin;
    }

    ....
    The transition by the button is carried out as follows.

    case ID_BUTTON_BACK: // Notifications sent by 'Back'
    switch(NCode) {
    case WM_NOTIFICATION_RELEASED:
    NScreen = W_SETTINGS;
    GUI_EndDialog(pMsg->hWin, 0);
    WM_HideWindow(hCurWin);
    WM_Exec();
    break;
    }
    break;

    ....

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!