1

After asking this question, I changed my code. It works, but when WM_PAINT paints the window and the cursor is moving in it, the painting is not done at the same time everywhere. Here you have a video to see it better. This is my WM_PAINT:

    //TV is a struct with the dimensions of the window.
    //BitmapBuffer is the bitmap containing the painting.

    static int cont;
    cont++;
    HDC HDc;
    PAINTSTRUCT ps;

    HDc = BeginPaint(identifier, &ps);

    Gdiplus::Graphics lienzo (HDc);

    AlphaBlend(HDc, 0, 0, TV.width+4, TV.height+4, buffer, 0, 0, TV.width+4, TV.height+4, CopyInfo);

    EndPaint(identifier, &ps);

Since the problem is when moving the mouse, maybe the WM_NCHITTEST message has something to do with it:

case WM_NCHITTEST: 

    POINTS point1 = MAKEPOINTS(lParam); 
    POINT point2;

    point2.x = point1.x;
    point2.y = point1.y;


    ScreenToClient(hwnd, &point2); 

    if (PtInRegion(region, point2.x, point2.y)) 
    {
        if (inWindow == false) //inWindow is true when the cursor is in the window
        {
            inWindow = true;
            TrackMouseEvent(&structure);
            Repaint(); //this function repaint the buffer and after call invalidrect
        }

        return HTCLIENT; 
    }
    else
    {
        if (inWindow == true)
        {
            inWindow = false;
            Repaint();
        }

        return HTTRANSPARENT; 
    }

    break;

Does anyone have an idea why this happens?

ouflak
  • 2,458
  • 10
  • 44
  • 49
julianix
  • 79
  • 7

1 Answers1

0

It's hard to see the problem, because your code doesn't define Repaint. However, you should be using InvalidateRect to tell Windows which area is being updated.
THAT SAID... Windows is hard to program for updating images with out using a double buffering technique. This is when you draw to a memory (bitmap) then bitblt the bitmap to the screen.

You find this answer useful Reduce flicker with GDI+ and C++

Tiger4Hire
  • 1,065
  • 5
  • 11