Saturday, December 16th 2017, 4:00pm UTC+1

You are not logged in.

  • Login
  • Register

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 41

1

Thursday, December 7th 2017, 7:51am

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/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
static TEXT_Handle _hText;
static WM_HWIN     _hDialog;

static void _cbText(WM_MESSAGE * pMsg) {
  /* Handle the message(s) needed */
  switch (pMsg->MsgId) {
  case 1100:
    printf("TXT::1100\n");
    break;  //no return here ... let parent do something
  }

  /* Default message handler */
  TEXT_Callback(pMsg);
}

static void _cbDialog(WM_MESSAGE * pMsg) {
  /* Handle the message(s) needed */
  switch (pMsg->MsgId) {
  case 1100:
    printf("DLG::1100\n");
    return;
  }

  /* Default message handler */
  WM_DefaultProc(pMsg);
}

void Test(void) {
  WM_HWIN hClient = WM_GetClientWindow(_hDialog);
    
  _hText = TEXT_CreateEx(0, 0, 80, 40, hClient, WM_CF_SHOW, 0x0, GUI_ID_TEXT0, 0);
  WM_SetCallback(_hText, _cbText);
  GUI_Delay(50);

  WM_SendMessageNoPara(_hText, 1100);
}


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

This post has been edited 2 times, last edit by "kenmux" (Dec 7th 2017, 7:54am)


SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 443

2

Thursday, December 7th 2017, 10:21am

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/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "DIALOG.h"

/*********************************************************************
*
*   	_cbText
*/
static void _cbText(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case 1100:
	//
	// Do something
	//
	WM_SendMessageNoPara(WM_GetParent(pMsg->hWin), 1100);  // Send message to the parent
	break;
  default:
	TEXT_Callback(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	_cbParent
*/
static void _cbParent(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_WHITE);
	GUI_Clear();
	break;
  case 1100:
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  WM_HWIN hWin;
  WM_HWIN hText;
  int 	xSize;
  int 	ySize;

  GUI_Init();
  xSize = LCD_GetXSize();
  ySize = LCD_GetYSize();
  hWin  = WM_CreateWindow(0, 0, xSize, ySize, WM_CF_SHOW, _cbParent, 0);
  hText = TEXT_CreateEx(20, 20, 80, 20, hWin, WM_CF_SHOW, 0, GUI_ID_TEXT0, "Text");
  WM_SetCallback(hText, _cbText);
  GUI_Delay(50);
  WM_SendMessageNoPara(hText, 1100);  // Send message to the TEXT widget
  while (1) {
	GUI_Delay(100);
  }
}


Regards
Sven

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 41

3

Thursday, December 7th 2017, 10:47am

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.