Tuesday, January 23rd 2018, 7:02am UTC+1

You are not logged in.

  • Login
  • Register

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 45

1

Thursday, January 11th 2018, 12:26pm

How to Make Window Transparent Again?

Hello,

Here's the scenario.
There's a window created by WM_CreateWindowAsChild().
It's transparent when not focused, but turn to white focused.
To make it clear, please refer to the images below:

1) The window is transparent for not focused (RIGHT!)


2) The window turns to white for focused (RIGHT!)


3) The window SHOULD turn to transparent again for not focused (WRONG!)


The question is, how to achieve this?
To ask all the windows behind it redraw themselves?
But, more than one window may be involved...

Please help! Thanks in advance!

Best regards,
Kenmux

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 469

2

Friday, January 12th 2018, 2:14pm

Hi,

You might try the code below. With the case WM_SET_FOCUS the window will be able to accept the focus and invalidates itself. Since the window was created with WM_CF_HASTRANS the background gets manager by the window below (WM_HBKWIN). In WM_PAINT we check if this window has the focus, if it has we clear it with white. If it doesn't has the focus we do simply nothing, the area gets drawn by the bk window.

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
70
71
72
73
/*********************************************************************
*
*   	_cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  GUI_COLOR   	Color;
  GUI_RECT    	Rect;
  GUI_PID_STATE * pState;
  static int  	Pressed;

  switch (pMsg->MsgId) {
  case WM_SET_FOCUS:
	pMsg->Data.v = 0;           	// Set to 0 if the window accepts the focus
	WM_Invalidate(pMsg->hWin);
	break;
  case WM_PAINT:
	if (WM_HasFocus(pMsg->hWin)) {
  	GUI_SetBkColor(GUI_WHITE);	// if the window has the focus fill with white
  	GUI_Clear();
  	Color = GUI_BLUE;         	// Set foreground color to blue
	} else {
  	Color = GUI_WHITE;        	// Set foreground color to White
	}
	GUI_SetColor(Color);
	WM_GetClientRect(&Rect);
	GUI_DrawRectEx(&Rect);      	// Draw a rectangle around the window
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	_cbBk
*/
static void _cbBk(WM_MESSAGE * pMsg) {
  switch (pMsg->MsgId) {
  case WM_PAINT:
	GUI_DrawGradientH(0, 0, LCD_GetXSize() - 1, LCD_GetYSize() - 1, GUI_DARKGRAY, GUI_LIGHTGRAY);
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  WM_HWIN hWin;

  GUI_Init();
  WM_SetCallback(WM_HBKWIN, _cbBk);
  hWin = WM_CreateWindowAsChild(10, 10, 200, 120, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, _cbWin, 0);
  while (1) {
	GUI_Delay(1000);
	if (WM_HasFocus(hWin)) {
  	WM_SetFocus(WM_HBKWIN);  // Set focus to another window
	} else {
  	WM_SetFocus(hWin);
	}
  }
}


Regards
Sven