Why the image drawed under WM_PAINT of window is beneath the window?

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

  • Why the image drawed under WM_PAINT of window is beneath the window?

    I tried to draw an image under WM_PAINT of callback of a window.
    But, I found the image was just beneath the window, is this as designed?
    The version of emWin library I used is 5.30.

    I created the window using the code as follows:

    C Source Code

    1. _hWindow = WINDOW_CreateEx (0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0x0, ID_WINDOW, _cbWindow);


    And the image was drawed under WM_PAINT of callback:

    C Source Code

    1. static void _cbWindow (WM_MESSAGE * pMsg) {
    2. switch (pMsg->MsgId) {
    3. case WM_PAINT:
    4. GUI_DrawBitmap (&_Bitmap, 0, 0);
    5. return;
    6. }
    7. }


    One more thing, when I created a dialog as a child of the window above, it was invisible;
    Only when I remove the flag WM_CF_HASTRANS, then it was visible, why?

    Thanks,
    Kenmux
  • Hi Kenmux,

    I tried to reproduce the beahvior you have described. But everthing is working as intended.

    I did this with the code below (of course another bitmap).

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * MainTask
    5. */
    6. static void _cbWindow (WM_MESSAGE * pMsg) {
    7. switch (pMsg->MsgId) {
    8. case WM_PAINT:
    9. GUI_DrawBitmap (&_Bitmap, 0, 0);
    10. return;
    11. }
    12. }
    13. /*********************************************************************
    14. *
    15. * MainTask
    16. */
    17. void MainTask(void) {
    18. GUI_Init();
    19. WINDOW_CreateEx (0, 0, 320, 240, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0x0, 0, _cbWindow);
    20. while (1) {
    21. GUI_Delay(10);
    22. }
    23. }
    Display All


    Please check if the code works on your side. The bitmap (of yourse you have to use your own) should be displayed in the topmost left corner.

    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.
  • Sorry for late! Thanks for your reply!

    I tested over and over again with the same result.
    I also tested with simulator, but this case could not be covered very well.
    And~I could not reproduce the issue of course.
    So, I decided to offer more details.

    First, the init code of background window as follows:

    C Source Code

    1. static void _cbBkWindow (WM_MESSAGE * pMsg) {
    2. switch (pMsg->MsgId) {
    3. case WM_PAINT:
    4. GUI_Clear ();
    5. break;
    6. default:
    7. WM_DefaultProc (pMsg);
    8. break;
    9. }
    10. }
    11. // Config background window
    12. WM_SetCreateFlags (WM_CF_MEMDEV);
    13. WM_EnableMemdev (WM_HBKWIN);
    14. _cbBkWindowNull = _cbBkWindowNull; //remove not used warning
    15. _cbBkWindowNull = WM_SetCallback (WM_HBKWIN, _cbBkWindow);
    Display All


    Then the window for drawing images (live image, trigger drawing by a message):

    C Source Code

    1. static void _cbWindow (WM_MESSAGE * pMsg) {
    2. static uint8_t _Draw = 0;
    3. switch (pMsg->MsgId) {
    4. case UI_MSG_DRAW:
    5. _Draw = 1;
    6. case WM_PAINT:
    7. if (_Draw == 1) {
    8. _Draw = 0;
    9. _DrawImage ();
    10. _SendEvent (ACK_MSG_DRAW);
    11. }
    12. return;
    13. }
    14. }
    15. _hWindow = WINDOW_CreateEx (0, 0, 240/*320*/, 240, WM_HBKWIN, WM_CF_SHOW/* | WM_CF_HASTRANS*/, 0x0, ID_WINDOW, _cbWindow);
    Display All


    In order to show the image beneath the window, I set the window size as 240x240, and opaque.
    The size of image for drawing is 320x240. As a result, the screenshot is attached.
    So, the question is, am I doing something wrong?

    IMG99999.BMP

    The post was edited 2 times, last by kenmux ().