how to set memory devices displayed before windows manager

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

    • how to set memory devices displayed before windows manager

      I’m beginner of emwin,always use simply way coding.

      I have created a windows, then created a memory device for display a circle before the windows.
      But the memory device displayed between the windows and desktop.

      How I set the memory device displayed foreground?
    • Hi,

      You could create a window instead of the memory device and bring this to the top.

      Here is a very basic example which shows how to create two windows, overwrite their callback function (more like setting it on creation) and draw within the callback function.

      They way you try it is very uncommen and not recommended. The problem is that if you draw something from outside of a callback function you can'r be really sure what happens (like will the drawing be visible?).

      Beside of that, memory devices can be a bit tricky in combination with the window manager because they use coordinates relative to the screen and not to windows. I would recommend to try them later once you are a bit more familiar with the window manager.

      Nonetheless, I make use of them in my example below.

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Static code
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * _cbBk
      11. */
      12. static void _cbBk(WM_MESSAGE * pMsg) {
      13. switch (pMsg->MsgId) {
      14. case WM_PAINT:
      15. GUI_SetBkColor(GUI_BLACK);
      16. GUI_Clear();
      17. break;
      18. default:
      19. WM_DefaultProc(pMsg);
      20. break;
      21. }
      22. }
      23. /*********************************************************************
      24. *
      25. * _cbWin0
      26. */
      27. static void _cbWin0(WM_MESSAGE * pMsg) {
      28. switch (pMsg->MsgId) {
      29. case WM_PAINT:
      30. GUI_SetBkColor(GUI_BLUE);
      31. GUI_Clear();
      32. break;
      33. default:
      34. WM_DefaultProc(pMsg);
      35. break;
      36. }
      37. }
      38. /*********************************************************************
      39. *
      40. * _cbWin1
      41. */
      42. static void _cbWin1(WM_MESSAGE * pMsg) {
      43. static GUI_MEMDEV_Handle hMem;
      44. int xPos;
      45. int yPos;
      46. switch (pMsg->MsgId) {
      47. case WM_CREATE:
      48. hMem = GUI_MEMDEV_Create(0, 0, 80, 80);
      49. GUI_MEMDEV_Select(hMem);
      50. GUI_SetBkColor(GUI_GREEN);
      51. GUI_Clear();
      52. GUI_SetColor(GUI_WHITE);
      53. GUI_DrawLine(0, 0, 79, 79);
      54. GUI_MEMDEV_Select(0);
      55. break;
      56. case WM_PAINT:
      57. GUI_SetBkColor(GUI_RED);
      58. GUI_Clear();
      59. xPos = WM_GetWindowOrgX(pMsg->hWin) + (WM_GetWindowSizeX(pMsg->hWin) - GUI_MEMDEV_GetXSize(hMem)) / 2;
      60. yPos = WM_GetWindowOrgY(pMsg->hWin) + (WM_GetWindowSizeY(pMsg->hWin) - GUI_MEMDEV_GetYSize(hMem)) / 2;
      61. GUI_MEMDEV_WriteAt(hMem, xPos, yPos);
      62. break;
      63. default:
      64. WM_DefaultProc(pMsg);
      65. break;
      66. }
      67. }
      68. /*********************************************************************
      69. *
      70. * Public code
      71. *
      72. **********************************************************************
      73. */
      74. /*********************************************************************
      75. *
      76. * MainTask
      77. */
      78. void MainTask(void) {
      79. WM_HWIN ahWin[2];
      80. int Index;
      81. GUI_Init();
      82. WM_SetCallback(WM_HBKWIN, _cbBk);
      83. ahWin[0] = WM_CreateWindowAsChild(10, 10, 100, 100, WM_HBKWIN, WM_CF_SHOW, _cbWin0, 0);
      84. ahWin[1] = WM_CreateWindowAsChild(30, 30, 100, 100, WM_HBKWIN, WM_CF_SHOW, _cbWin1, 0);
      85. Index = 0;
      86. while (1) {
      87. GUI_Delay(1000);
      88. WM_BringToTop(ahWin[Index]);
      89. Index ^= 1;
      90. }
      91. }
      92. /*************************** End of file ****************************/
      Display All
    • Hi,

      To avoid flickering I recommend to use multi buffering. This is only available with the GUIDRV_Lin driver and has to be configured in the LCDConf.c. Once set up all you have to do is to call WM_MULTIBUF_Enable(1) right after GUI_Init().

      If you are not using the GUIDRV_Lin driver you can use a driver with a cache. This is available for most indirect driver.

      Regards,
      Sven