WM_GetInsideRect results when WM_CF_HASTRANS is used

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

    • WM_GetInsideRect results when WM_CF_HASTRANS is used

      I use emWin 5.40 (STemWin provided by ST)

      I tried this in the simulator:

      C Source Code

      1. #include "GUI.h"
      2. #include <stdlib.h>
      3. GUI_RECT Rect1;
      4. GUI_RECT Rect2;
      5. void Callback1(WM_MESSAGE *pMsg)
      6. {
      7. WM_HWIN hWin;
      8. hWin = pMsg->hWin;
      9. switch (pMsg->MsgId)
      10. {
      11. case WM_PAINT:
      12. WM_GetInsideRect(&Rect1);
      13. GUI_SetBkColor(GUI_BLACK);
      14. GUI_SetColor(GUI_WHITE);
      15. GUI_ClearRectEx(&Rect1);
      16. GUI_DrawRectEx(&Rect1);
      17. break;
      18. default:
      19. WM_DefaultProc(pMsg);
      20. break;
      21. }
      22. }
      23. void Callback2(WM_MESSAGE *pMsg)
      24. {
      25. WM_HWIN hWin;
      26. hWin = pMsg->hWin;
      27. switch (pMsg->MsgId)
      28. {
      29. case WM_PAINT:
      30. WM_GetInsideRect(&Rect2);
      31. GUI_SetBkColor(GUI_BLACK);
      32. GUI_SetColor(GUI_WHITE);
      33. GUI_ClearRectEx(&Rect2);
      34. GUI_DrawRectEx(&Rect2);
      35. break;
      36. default:
      37. WM_DefaultProc(pMsg);
      38. break;
      39. }
      40. }
      41. void MainTask(void)
      42. {
      43. GUI_Init();
      44. GUI_SetBkColor(GUI_GRAY_3F);
      45. GUI_Clear();
      46. WM_HWIN hWin1, hWin2;
      47. hWin1 = WM_CreateWindowAsChild(10, 10, 80, 45, WM_HBKWIN,
      48. WM_CF_SHOW , Callback1, 0);
      49. hWin2 = WM_CreateWindowAsChild(10, 60, 80, 45, WM_HBKWIN,
      50. WM_CF_SHOW | WM_CF_HASTRANS, Callback2, 0);
      51. GUI_Delay(20);
      52. while(1)
      53. {
      54. GUI_Delay(2000);
      55. }
      56. }
      Display All


      the result is:
      [img]https://s18.postimg.org/tb7t46r1l/hastrans_behaviour.png[/img]

      and inside the dubugger rectangles are:
      [img]https://s18.postimg.org/qtw1wzcax/debugger_rect.png[/img]

      Why, when I set the WM_CF_HASTRANS flag, does the window I created seem to have the wrong size?

      best regards
      Max
    • Hi,

      With the transparency flag set a window gets draw as part of the window behind. In this case it gets drawn as part of the WM_HBKWIN. This means that when inside the callback function (Callback2) the WM_HBKWIN is selected. The function WM_GetInsideRect() does not perform any checks regarding the selected window and if a window is transparent or not. So, this function simply returns the rectangle of the currently selected window (WM_HBKWIN).

      You can do the following, either use WM_GetInsideRectEx() with the handle of the window to be drawn (pMsg->hWin) or use WM_GetClientRect(). The second function checks if there is a transparent window. If there is one it gets selected.

      Regards
      Sven