Monday, December 11th 2017, 11:56pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

giusloq

Beginner

Date of registration: Feb 5th 2015

Posts: 58

1

Thursday, February 5th 2015, 12:19pm

How to close a window a pass a message to another window

I'm using emWin libraries on a NXP board with a single-task (polling loop).

I have a visible/active window (Main Window) that covers all the display and a button inside. When the user press the button, I'd like to create and show another window (Slave Window), created on-the-fly in WM_NOTIFICATION_RELEASED message. The Slave Window covers the entire display and it should be on top of the Main Window.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
static void
cbBackgroundWin(WM_MESSAGE *pMsg)
{
	WM_HWIN hWin = pMsg->hWin;

	switch(pMsg->MsgId) {
		case WM_NOTIFY_PARENT: {
			switch(pMsg->Data.v) {
				case WM_NOTIFICATION_RELEASED:
					hDialog = dialog_entercode_create(hWin, code, sizeof(code) - 1);
					WM_ShowWindow(hDialog);
					break;
			}
			break;
		}
		case WM_USER:
			?????
			break;
		default:
			WM_DefaultProc(pMsg);
	}
}


dialog_entercode_create() creates and returns the handle of the newly created Slave Window. It isn't shown, so the call WM_ShowWindow(hDialog). When finished, the user press a button on Slave Window and the effect should be to delete Slave Window and automatically show again the Main Window.
I tried to send an application-defined message (WM_USER) from the callback function of the Slave Window to the Main Window. In the WM_USER code of the Main Window, I tried to call WM_DeleteWindow(hDialog), but the application crashes. I think because the messages aren't send through a queue mechanism, but inside the WM_SendMessage(). So, when the Main Window calls WM_DeleteWindow(), the Slave Window is yet active and its callback is running so it can't be deleted.

I can call WM_HideWindow() instead of WM_DeleteWindow(), but I'd like to completely deallocate the Slave Window after the user has finished using it.

The problem is similar to a non-blocking Dialog window, but I couldn't understand how it works with Dialogs feature of emWin. Could I call GUI_EndDialog() with a custom window not created with GUI_CreateDialogBox()?

SEGGER - Adrian

Super Moderator

Date of registration: May 26th 2009

Posts: 994

2

Monday, February 9th 2015, 2:48pm

Hello,

WM_DELETE is the last message sent to a window just before it gets deleted. WM_NOTIFY_PARENT / WM_WM_NOTIFICATION_CHILD_DELETED is the last notification regarding a certain window sent to its parent window just before the child window gets deleted. I assume you want to react to one of those messages in order to let the parent window know about the child being deleted.

Please note that newly created windows are not shown by default. Either the create flag WM_CF_SHOW is used at creation or the function WM_ShowWindow() is called after the window was created.

Best regards,
Adrian

giusloq

Beginner

Date of registration: Feb 5th 2015

Posts: 58

3

Tuesday, February 10th 2015, 11:27am

Quoted

"WM_DELETE is the last message sent to a window just before it gets
deleted. WM_NOTIFY_PARENT / WM_WM_NOTIFICATION_CHILD_DELETED is the last
notification regarding a certain window sent to its parent window just
before
the child window gets deleted. I assume you want to react to one of
those messages in order to let the parent window know about the child
being deleted."
I try to reformulate the question again. I have two windows: Main Window and Aux Window. Both have a button.
Main Button (button on Main Window) creates and shows the Aux Window, overwriting the Main Window. The Aux button (the button in the Aux Window) closes the Aux Window and communicates to the Main Window the event.

In WM_NOTIFICATION_PARENT / WM_NOTIFICATION_RELEASED of Aux Window, I send an application defined message (WM_USER) to Main Window. I tried to call WM_DeleteWindow(Aux_Window) from there, but I can't. I think because Main Window callback is called from Aux Window callback that can't be self-deleted.

So the question is: how to delete a window from inside its callback?

SEGGER - Adrian

Super Moderator

Date of registration: May 26th 2009

Posts: 994

4

Wednesday, February 11th 2015, 9:47am

Hello,

Deleting a window from inside a callback function should actually work. In general it is the intended way to perform actions from inside callback functions when using the Window Manager.

Could you please verify the correct window handle is passed to the function WM_Delete()?

Best regards,
Adrian