Sunday, February 25th 2018, 2:36am UTC+1

You are not logged in.

  • Login
  • Register

mastupristi

Beginner

Date of registration: Feb 18th 2016

Posts: 21

1

Thursday, February 8th 2018, 12:15am

How to get position of a child window in window coordinates

Hallo,
How to get the position of a child window in its parent window coordinates?

best regards
MAx

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 496

2

Thursday, February 8th 2018, 2:02pm

Hi,

To get the position of a window relative to its parent simply subtract the screen position of the parent from the screen position of the child window.

Try this:

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
67
68
69
#include "DIALOG.h"

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_cbWinParent
*/
static void _cbWinParent(WM_MESSAGE * pMsg) {
  WM_HWIN  hChild;
  GUI_RECT Rect;
  int  	xPos;
  int  	yPos;

  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_RED);
	GUI_Clear();
	hChild = WM_GetFirstChild(pMsg->hWin);
	xPos = WM_GetWindowOrgX(hChild) - WM_GetWindowOrgX(pMsg->hWin);
	yPos = WM_GetWindowOrgY(hChild) - WM_GetWindowOrgY(pMsg->hWin);
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	_cbBk
*/
static void _cbWinChild(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_SetBkColor(GUI_GREEN);
	GUI_Clear();
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  WM_HWIN hWinParent;
  WM_HWIN hWinChild;

  GUI_Init();
  hWinParent = WM_CreateWindowAsChild(10, 10, 150, 150, WM_HBKWIN, WM_CF_SHOW, _cbWinParent, 0);
  hWinChild  = WM_CreateWindowAsChild(10, 10, 50, 50, hWinParent, WM_CF_SHOW, _cbWinChild, 0);
  while (1) {
	GUI_Delay(100);
  }
}


Regards
Sven