Window with transparency

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

  • Window with transparency

    Hi,

    is it possible to define a transparent background for a whole window? The window is created with "WM_CreateWindowAsChild(...)"
    If yes, how do I achieve this!

    Thanks,
    Johannes
  • Hi,

    Of course, you can set the window as transparent. Simply set the create WM_CF_HASTRANS when creating the window. While in WM_PAINT of the window avoid things like

    C Source Code

    1. GUI_SetBkColor(GUI_RED);
    2. GUI_Clear();


    This will overwrite the background and the window won't be transparent any longer.

    Here is a short sample with a transparent window (it has a white frame) which can be dragged around.

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Local code
    5. *
    6. **********************************************************************
    7. */
    8. /*********************************************************************
    9. *
    10. * _cbWin
    11. */
    12. static void _cbWin(WM_MESSAGE * pMsg) {
    13. GUI_RECT Rect;
    14. switch (pMsg->MsgId) {
    15. case WM_PAINT:
    16. WM_GetClientRect(&Rect);
    17. GUI_DrawRectEx(&Rect);
    18. break;
    19. default:
    20. WM_DefaultProc(pMsg);
    21. break;
    22. }
    23. }
    24. /*********************************************************************
    25. *
    26. * _cbBk
    27. */
    28. static void _cbBk(WM_MESSAGE * pMsg) {
    29. int xSize;
    30. int ySize;
    31. switch (pMsg->MsgId) {
    32. case WM_PAINT:
    33. xSize = LCD_GetXSize() - 1;
    34. ySize = LCD_GetYSize() - 1;
    35. GUI_DrawGradientV(0, 0, xSize, ySize, GUI_BLACK, GUI_GRAY);
    36. break;
    37. default:
    38. WM_DefaultProc(pMsg);
    39. break;
    40. }
    41. }
    42. /*********************************************************************
    43. *
    44. * Public code
    45. *
    46. **********************************************************************
    47. */
    48. /*********************************************************************
    49. *
    50. * MainTask
    51. */
    52. void MainTask(void) {
    53. int xSize;
    54. int ySize;
    55. GUI_Init();
    56. WM_MULTIBUF_Enable(1);
    57. WM_MOTION_Enable(1);
    58. WM_SetCallback(WM_HBKWIN, _cbBk);
    59. xSize = LCD_GetXSize();
    60. ySize = LCD_GetYSize();
    61. WM_SetSize(WM_HBKWIN, xSize, ySize);
    62. WM_CreateWindow(20, 20, 100, 100, WM_CF_SHOW | WM_CF_HASTRANS | WM_CF_MOTION_X | WM_CF_MOTION_Y, _cbWin, 0);
    63. while (1) {
    64. GUI_Delay(100);
    65. }
    66. }
    Display All


    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.