Message cannot be posted from child to parent via default callback?

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

  • Message cannot be posted from child to parent via default callback?

    Hello all,

    In my opinion, the message will be posted from child to parent via default callback.
    Is it right? To make it clear, I wrote the test code as followed:

    C Source Code

    1. static TEXT_Handle _hText;
    2. static WM_HWIN _hDialog;
    3. static void _cbText(WM_MESSAGE * pMsg) {
    4. /* Handle the message(s) needed */
    5. switch (pMsg->MsgId) {
    6. case 1100:
    7. printf("TXT::1100\n");
    8. break; //no return here ... let parent do something
    9. }
    10. /* Default message handler */
    11. TEXT_Callback(pMsg);
    12. }
    13. static void _cbDialog(WM_MESSAGE * pMsg) {
    14. /* Handle the message(s) needed */
    15. switch (pMsg->MsgId) {
    16. case 1100:
    17. printf("DLG::1100\n");
    18. return;
    19. }
    20. /* Default message handler */
    21. WM_DefaultProc(pMsg);
    22. }
    23. void Test(void) {
    24. WM_HWIN hClient = WM_GetClientWindow(_hDialog);
    25. _hText = TEXT_CreateEx(0, 0, 80, 40, hClient, WM_CF_SHOW, 0x0, GUI_ID_TEXT0, 0);
    26. WM_SetCallback(_hText, _cbText);
    27. GUI_Delay(50);
    28. WM_SendMessageNoPara(_hText, 1100);
    29. }
    Display All


    The test result is, the message cannot be posted from child to parent via default callback?!!
    Did I do something wrong? If not, then some strange issues in my project do make sense...
    My emWin version is: v5.44b

    Thanks,
    Kenmux

    The post was edited 2 times, last by kenmux ().

  • Hi,

    Do I get you right that you expect that a message which is not handled by a child should be passed to its parent?

    but this is not the case. If you send a message to a specific window, only that single window will receive the message. If you want that the parent react on a non-handled message you have to manually pass it to the parent.

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * _cbText
    5. */
    6. static void _cbText(WM_MESSAGE * pMsg) {
    7. switch (pMsg->MsgId) {
    8. case 1100:
    9. //
    10. // Do something
    11. //
    12. WM_SendMessageNoPara(WM_GetParent(pMsg->hWin), 1100); // Send message to the parent
    13. break;
    14. default:
    15. TEXT_Callback(pMsg);
    16. break;
    17. }
    18. }
    19. /*********************************************************************
    20. *
    21. * _cbParent
    22. */
    23. static void _cbParent(WM_MESSAGE * pMsg) {
    24. switch (pMsg->MsgId) {
    25. case WM_PAINT:
    26. GUI_SetBkColor(GUI_WHITE);
    27. GUI_Clear();
    28. break;
    29. case 1100:
    30. break;
    31. default:
    32. WM_DefaultProc(pMsg);
    33. break;
    34. }
    35. }
    36. /*********************************************************************
    37. *
    38. * Public code
    39. *
    40. **********************************************************************
    41. */
    42. /*********************************************************************
    43. *
    44. * MainTask
    45. */
    46. void MainTask(void) {
    47. WM_HWIN hWin;
    48. WM_HWIN hText;
    49. int xSize;
    50. int ySize;
    51. GUI_Init();
    52. xSize = LCD_GetXSize();
    53. ySize = LCD_GetYSize();
    54. hWin = WM_CreateWindow(0, 0, xSize, ySize, WM_CF_SHOW, _cbParent, 0);
    55. hText = TEXT_CreateEx(20, 20, 80, 20, hWin, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Text");
    56. WM_SetCallback(hText, _cbText);
    57. GUI_Delay(50);
    58. WM_SendMessageNoPara(hText, 1100); // Send message to the TEXT widget
    59. while (1) {
    60. GUI_Delay(100);
    61. }
    62. }
    Display All


    Regards
    Sven
    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.
  • Thanks for your reply, Sven
    Okay, I see.
    This is not the same as handling a key message, right?
    A key message will be posted to the focused window.
    If it is not handled by the focused window, it will be posted to its parent.