How to Make Window Transparent Again?

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

  • 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
  • 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 Source Code

    1. /*********************************************************************
    2. *
    3. * _cbWin
    4. */
    5. static void _cbWin(WM_MESSAGE * pMsg) {
    6. GUI_COLOR Color;
    7. GUI_RECT Rect;
    8. GUI_PID_STATE * pState;
    9. static int Pressed;
    10. switch (pMsg->MsgId) {
    11. case WM_SET_FOCUS:
    12. pMsg->Data.v = 0; // Set to 0 if the window accepts the focus
    13. WM_Invalidate(pMsg->hWin);
    14. break;
    15. case WM_PAINT:
    16. if (WM_HasFocus(pMsg->hWin)) {
    17. GUI_SetBkColor(GUI_WHITE); // if the window has the focus fill with white
    18. GUI_Clear();
    19. Color = GUI_BLUE; // Set foreground color to blue
    20. } else {
    21. Color = GUI_WHITE; // Set foreground color to White
    22. }
    23. GUI_SetColor(Color);
    24. WM_GetClientRect(&Rect);
    25. GUI_DrawRectEx(&Rect); // Draw a rectangle around the window
    26. break;
    27. default:
    28. WM_DefaultProc(pMsg);
    29. break;
    30. }
    31. }
    32. /*********************************************************************
    33. *
    34. * _cbBk
    35. */
    36. static void _cbBk(WM_MESSAGE * pMsg) {
    37. switch (pMsg->MsgId) {
    38. case WM_PAINT:
    39. GUI_DrawGradientH(0, 0, LCD_GetXSize() - 1, LCD_GetYSize() - 1, GUI_DARKGRAY, GUI_LIGHTGRAY);
    40. break;
    41. default:
    42. WM_DefaultProc(pMsg);
    43. break;
    44. }
    45. }
    46. /*********************************************************************
    47. *
    48. * Public code
    49. *
    50. **********************************************************************
    51. */
    52. /*********************************************************************
    53. *
    54. * MainTask
    55. */
    56. void MainTask(void) {
    57. WM_HWIN hWin;
    58. GUI_Init();
    59. WM_SetCallback(WM_HBKWIN, _cbBk);
    60. hWin = WM_CreateWindowAsChild(10, 10, 200, 120, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, _cbWin, 0);
    61. while (1) {
    62. GUI_Delay(1000);
    63. if (WM_HasFocus(hWin)) {
    64. WM_SetFocus(WM_HBKWIN); // Set focus to another window
    65. } else {
    66. WM_SetFocus(hWin);
    67. }
    68. }
    69. }
    Display All


    Regards
    Sven