I have created a emwin window, which has a jpg image as background. The code is as the following:
Display All
In order to speed up the PAINT process, I use MEMDEV to display the image.
The strange thing is:
1. When I enable macro CREATE_MEMDEV_IN_PREPAINT, the background image can not be displayed if I call 'WM_SetCreateFlags(WM_CF_MEMDEV);' before the window creation. Without this function call, everything looks fine.
2. When I enable macro CREATE_MEMDEV_IN_INIT, both works with/without 'WM_SetCreateFlags(WM_CF_MEMDEV);' call.
I don't understand, It looks the same. Any ideas?
C Source Code
- GUI_MEMDEV_Handle GH_LoadJPEG2MemDev(const char *filename, int x, int y)
- {
- HANDLE hFile;
- DWORD readBytes;
- DWORD fileSize;
- char *acBuffer;
- GUI_HMEM hMem;
- GUI_MEMDEV_Handle hMemJPEG;
- GUI_JPEG_INFO jpegInfo;
- hFile = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
- fileSize = GetFileSize(hFile, NULL);
- hMem = GUI_ALLOC_AllocZero(fileSize);
- acBuffer = GUI_ALLOC_h2p(hMem);
- ReadFile(hFile, acBuffer, fileSize, &readBytes, NULL);
- GUI_JPEG_GetInfo(acBuffer, fileSize, &jpegInfo);
- hMemJPEG = GUI_MEMDEV_CreateEx(0, 0, jpegInfo.XSize, jpegInfo.YSize, GUI_MEMDEV_HASTRANS);
- GUI_MEMDEV_Select(hMemJPEG);
- GUI_JPEG_Draw(acBuffer, fileSize, x, y);
- GUI_MEMDEV_Select(0);
- GUI_ALLOC_Free(hMem);
- CloseHandle(hFile);
- return hMemJPEG;
- }
- /*********************************************************************
- * *
- * SEGGER Microcontroller GmbH *
- * Solutions for real time microcontroller applications *
- * *
- **********************************************************************
- * *
- * C-file generated by: *
- * *
- * GUI_Builder for emWin version 6.24 *
- * Compiled Jan 18 2022, 14:47:28 *
- * (c) 2022 SEGGER Microcontroller GmbH *
- * *
- **********************************************************************
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- */
- // USER START (Optionally insert additional includes)
- // USER END
- #include "DIALOG.h"
- #include "GuiIncludes.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- enum {
- ID_WINDOW_0 = (GUI_ID_USER + 0x02),
- };
- static GUI_MEMDEV_Handle jpegHandle;
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
- };
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg)
- {
- const void * pData;
- WM_HWIN hItem;
- U32 FileSize;
- WM_HWIN hWin = pMsg->hWin;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- #ifdef CREATE_MEMDEV_IN_INIT
- jpegHandle = GH_LoadJPEG2MemDev(GH_GetImageFilePath("home.jpg"), 0, 0);
- #endif
- break;
- case WM_PRE_PAINT:
- #ifdef CREATE_MEMDEV_IN_PREPAINT
- jpegHandle = GH_LoadJPEG2MemDev(GH_GetImageFilePath("home.jpg"), 0, 0);
- #endif
- break;
- case WM_PAINT:
- GUI_MEMDEV_WriteAt(jpegHandle, 0, 0);
- break;
- case WM_POST_PAINT:
- GUI_MEMDEV_Delete(jpegHandle);
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * CreateWindow
- */
- WM_HWIN CreateWindow_HomeDetect(void)
- {
- WM_HWIN hWin;
- hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- WM__ahWinFocus[0] = hWin;
- return hWin;
- }
The strange thing is:
1. When I enable macro CREATE_MEMDEV_IN_PREPAINT, the background image can not be displayed if I call 'WM_SetCreateFlags(WM_CF_MEMDEV);' before the window creation. Without this function call, everything looks fine.
2. When I enable macro CREATE_MEMDEV_IN_INIT, both works with/without 'WM_SetCreateFlags(WM_CF_MEMDEV);' call.
I don't understand, It looks the same. Any ideas?