Message Box

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

  • Message Box

    Hi

    I want to create a message box that closes automatically after a preset time.

    I have used MESSAGEBOX_Create to create a message box and return a handle which I use to assign it a callback.
    I then created a timer to send the message box a timer msg.

    In the callback, on a WM_TIMER msg I call GUI_EndDialog(pMsg->hWin, 0);

    While this closes the message box, the GUI hangs after this.

    I have tried making the message box non modal, closing it by sending it a button msg, but the GUI still hangs after this.

    Suggestions welcome?
    Thanks
    Lawrence
  • Hi,

    try the following:

    C Source Code

    1. #include "GUI.h"
    2. #include "MESSAGEBOX.h"
    3. static void _cbWin(WM_MESSAGE * pMsg) {
    4. WM_HWIN hWin, hBox;
    5. WM_HTIMER hTimer;
    6. switch (pMsg->MsgId) {
    7. case WM_TIMER:
    8. /*
    9. * Delete timer, dummy window and message box
    10. */
    11. hTimer = (WM_HTIMER)pMsg->Data.v;
    12. hWin = pMsg->hWin;
    13. WM_GetUserData(hWin, &hBox, sizeof(hBox));
    14. WM_DeleteTimer(hTimer);
    15. WM_DeleteWindow(hBox);
    16. WM_DeleteWindow(hWin);
    17. break;
    18. }
    19. }
    20. void MainTask(void) {
    21. WM_HWIN hWin, hBox;
    22. GUI_Init();
    23. /*
    24. * Make sure desktop will be redrawn
    25. */
    26. WM_SetDesktopColor(GUI_BLACK);
    27. /*
    28. * Create destination window (dummy) for timer message
    29. * with additional user data for message box handle
    30. */
    31. hWin = WM_CreateWindow(0, 0, 0, 0, 0, _cbWin, sizeof(hBox));
    32. /*
    33. * Create modal message box
    34. */
    35. hBox = MESSAGEBOX_Create("Closes in a\n"
    36. "few seconds...",
    37. "Message", GUI_MESSAGEBOX_CF_MODAL);
    38. /*
    39. * Store message box handle in user data
    40. */
    41. WM_SetUserData(hWin, &hBox, sizeof(hBox));
    42. /*
    43. * Create timer
    44. */
    45. WM_CreateTimer(hWin, 0, 2000, 0);
    46. while (1) {
    47. GUI_Delay(100);
    48. }
    49. }
    Display All


    Regards
    DJJ