Tuesday, January 23rd 2018, 4:43am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 45

1

Monday, December 11th 2017, 9:21am

How to make sure an image is removed from screen?

Hello all,

I wrote some code as follows:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
static void _cbImageShtr(WM_MESSAGE * pMsg) {
  /* Local variable(s) */
  WM_HWIN   hWin;
  uint8_t   UserData[20];
  uint8_t * pData;
  int       Index;
  int       NumItems;
  int       Period;
  size_t    Offset;

  /* Handle the message(s) needed */
  switch (pMsg->MsgId) {
  case WM_TIMER:
    hWin = pMsg->hWin;
    if (IMAGE_GetUserData(hWin, UserData, sizeof(UserData))) {
      pData = UserData;
      Offset = sizeof(int);
      Period = *(int *)pData;
      pData += Offset;
      NumItems = *(int *)pData;
      pData += Offset;
      Index = *(int *)pData + 1;
      if (Index < NumItems) {
        *(int *)pData = Index;
        pData += Offset;
        IMAGE_SetBitmap(hWin, ((void **)*((intptr_t *)pData))[Index]);
        IMAGE_SetUserData(hWin, UserData, sizeof(UserData));
        WM_RestartTimer(pMsg->Data.v, Period);
      } else {
        WM_DeleteTimer(pMsg->Data.v);
        WM_HideWindow(hWin);
        WM_DeleteWindow(hWin);
      }
    }
    return;
  case WM_DELETE:
    _hImageShtr = WM_HMEM_NULL;
    WM_SendMessageNoPara(_hColorbar, UI_MSG_SCREEN_DUMP);
    break;
  }

  /* Default message handler */
  IMAGE_Callback(pMsg);
}


It will display a serial of images, then tell emWin to get a screenshot.
The problem is that, sometimes the last image showed in the screenshot.
But, look into the code, this should not happen, right? For it's hidden then deleted:


C/C++ Source code

1
2
        WM_HideWindow(hWin);
        WM_DeleteWindow(hWin);



So, the question is, how to make sure that an image is removed from screen?

PS:
I get a screenshot by copy the visible buffer of emWin, not using BMP_Serialize() for its speed.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 469

2

Tuesday, December 12th 2017, 11:24am

Hi,

In general I don't recommend to use GUI_Exec() within a callback function, but you can try to call GUI_Exec() right after WM_HideWindow().

Regards
Sven

kenmux

Beginner

Date of registration: Jan 18th 2016

Posts: 45

3

Friday, January 5th 2018, 2:56pm

Thanks for your reply!
I add GUI_Delay(5), then it seems okay now.