how about emwin WM_PAINT trigger mechanism?

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

    • how about emwin WM_PAINT trigger mechanism?

      fresh man alway have much question. :)

      A window has been created.
      1. If the text of a text label of the window changed, wether a WM_PAINT message will be sent automatically?
      2. the message "WM_POST_PAINT", is "Send to a window after the last WM_PAINT message is sent",
      for user's code should be code in WM_POST_PAINT or WM_PRE_PAINT instead of WM_PAINT?

      My english is so good. <X

      thanks.
    • I set a break point at WM_PAINT, and the point will be broken several times at the first.
      After the first period, the point never be broken.

      So it means if a window be create, the WM_PAINT will be sent many times during the "create process"?
    • case WM_PAINT:
      hMem00_Face = GUI_MEMDEV_Create(141, 15, 76, 76);
      GUI_MEMDEV_Select(hMem00_Face);
      GUI_SetColor(GUI_WHITE);
      GUI_SetPenSize(16);
      GUI_AA_DrawRoundedRect(149, 23, 209, 83, 30);
      GUI_MEMDEV_Select(0);
      break;

      The hMem00_Face is a global var, I count it will be broken 21 times if I set a break point at the "GUI_MEMDEV_Create" line.
      My code is compliled with no Optimzation Level 0.
      The code as it, the result is right. But I use the code below, the result is error, acted as no any effect.

      case WM_PAINT:
      if (WM_HMEM_NULL == hMem00_Face)
      {
      hMem00_Face = GUI_MEMDEV_Create(141, 15, 76, 76);
      }
      GUI_MEMDEV_Select(hMem00_Face);
      GUI_SetColor(GUI_WHITE);
      GUI_SetPenSize(16);
      GUI_AA_DrawRoundedRect(149, 23, 209, 83, 30);
      GUI_MEMDEV_Select(0);
      break;

      The hMem00_Face is init as WM_HMEM_NULL.

      So if I use the fisrt codes, is there a memory leak happen? And how I delete the memory device?
    • Hi,
      1. If the text of a text label of the window changed, wether a WM_PAINT message will be sent automatically?
      Yes, a window will be marked as invalid on creation and receives as many WM_PAINT messages as neccessary to draw the window. A window can receive multiple WM_PAINT messages, due to clipping. The clipping mechanism will leave out areas which don't have to be drawn (like a opaque window on top of the window to be drawn).

      Take a look this simple application. Each time the background window gets a WM_PAINT message it uses a different color. It will receive 4 messages, one for each area around the child window.

      C Source Code

      1. #include "WM.h"
      2. void _cbBk(WM_MESSAGE * pMsg) {
      3. GUI_COLOR aColor[] = { GUI_BLUE, GUI_GREEN, GUI_RED, GUI_CYAN, GUI_MAGENTA, GUI_YELLOW };
      4. static int Index;
      5. switch (pMsg->MsgId) {
      6. case WM_PAINT:
      7. GUI_SetBkColor(aColor[Index++]);
      8. if (Index == GUI_COUNTOF(aColor)) {
      9. Index = 0;
      10. }
      11. GUI_Clear();
      12. break;
      13. default:
      14. WM_DefaultProc(pMsg);
      15. }
      16. }
      17. void _cbWin(WM_MESSAGE * pMsg) {
      18. switch (pMsg->MsgId) {
      19. case WM_PAINT:
      20. GUI_Clear();
      21. GUI_DispStringAt("Hello world!", 10, 10);
      22. break;
      23. default:
      24. WM_DefaultProc(pMsg);
      25. }
      26. }
      27. void MainTask(void) {
      28. WM_HWIN hWin, hWinBk;
      29. GUI_Init();
      30. hWinBk = WM_CreateWindowAsChild(0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW, _cbBk, 0);
      31. hWin = WM_CreateWindowAsChild(10, 10, 100, 100, hWinBk, WM_CF_SHOW, _cbWin, 0);
      32. while (1) {
      33. GUI_Delay(100);
      34. }
      35. }
      Display All




      2. the message "WM_POST_PAINT", is "Send to a window after the last WM_PAINT message is sent",
      for user's code should be code in WM_POST_PAINT or WM_PRE_PAINT instead of WM_PAINT?
      WM_PAINT is the proper position to place you code if you want to draw something in a window. The pre- and post-messages are seldom used and more for preparing a drawing operation.

      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.