WM_SetDesktopColor behaviour

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

    • WM_SetDesktopColor behaviour

      I have a doubt on how WM_SetDesktopColor works.I am using this API to clear the background but untill unless you call GUI_Exec right after that it will not work as expected.
      I am calling WM_SetDesktopColor after deleting 1 window and before creating the other one. but i have to call GUI_Exec() just after this function to clear the background.
      if i am calling this way its not working

      GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

      But is working this way
      GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);

      Please clarify. If behavior is like this then we will end up in having so many GUI_Exec(), which is not correct.
    • Hi,

      This is the intended behavior.

      When using the Window Manager everything gets managed within GUI_Exec().

      Most of the applications have a super loop which periodically calls GUI_Exec() or GUI_Delay() (GUI_Delay() calls GUI_Exec()). This loop takes care about updating the screen content.

      Below is a very simple application which shows how it works. The desktop color gets used to clear the screen when the window gets deleted. Also, please note that the window gets not directly visible when calling WM_CreateWindow(). Just while calling GUI_Delay() it gets created. The same is true for WM_DeleteWindow(). Dialogs behave in the same way (in the end they are just windows).

      Source Code

      1. #include "WM.h"
      2. static void _cbWin(WM_MESSAGE * pMsg) {
      3. switch (pMsg->MsgId) {
      4. case WM_PAINT:
      5. GUI_SetBkColor(GUI_RED);
      6. GUI_Clear();
      7. break;
      8. default:
      9. WM_DefaultProc(pMsg);
      10. break;
      11. }
      12. }
      13. void MainTask(void) {
      14. WM_HWIN hWin;
      15. GUI_Init();
      16. WM_SetDesktopColor(GUI_BLACK); // Color set only once
      17. hWin = 0;
      18. while (1) {
      19. GUI_Delay(1000); // Update, window gets visible or invisible
      20. if (WM_IsWindow(hWin)) {
      21. WM_DeleteWindow(hWin); // Delete window, nothing happens
      22. } else {
      23. //
      24. // Create a window, nothing happens
      25. //
      26. hWin = WM_CreateWindowAsChild(10, 10, 50, 50, WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
      27. }
      28. }
      29. }
      Display All
      Also it is not necessary to call WM_SetDesktopColor() multiple times. The Window Manager automatically clears the background with the set color when a dialog in the foreground gets deleted. Of course, this will only happen when calling GUI_Exec().

    • New

      Hi Sven,
      I tried callling WM_SetDesktopColor only once after GUI_Init. but what i see is it is not working for other window if i am not calling it again after deleting one window and creating other.
      I am also using super loop for updating the screens but what i understood is , if call WM_SetDesktopColor() then create a new window, there if i wait for that loop to execute the GUI_Exec() , background window won't be redrawn. Thats why i need to call GUI_exec() immediately. I have some 5 screen. Is it ok to call WM_SetDesktopColor() with gui_exec() every time after deleting one screen and creating other.