Win32 WM_MOUSEMOVE problem with redraw

Claudio La Rosa 21 Reputation points
2022-01-25T13:11:07.267+00:00

Hi to all,
I have a problem with redraw (or handle redraw message) with a win32 window in C++.

I open a normal (WS_OVERLAPPEDWINDOW) window and I handle the messages with a standard code.

My goal is to move a simple sketch (a rectangle painted with FillRect() ) with drag the mouse.

For this reason, I handle the WM_MOUSEMOVE message. When I obtain a WM_MOUSEMOVE, I get the X and Y coords, update the position of my rectangle and redraw it (I tried with two methosd: call redrawWindows() or redraw directly the rectangle in WM_MOUSEMOVE method, between GetDC() and ReleaseDC() ).

This works quite well only that after a few seconds of dragging the mouse, the drawing of the window no longer occurs. The client area remains white and I can no longer see my rectangle.

I cannot understand the reason for this behavior.

Do you have any suggestions on why and how to solve the problem?
Thank you all.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,637 questions
{count} votes

Accepted answer
  1. Castorix31 83,206 Reputation points
    2022-01-25T13:43:50.65+00:00

    An usual method for Drag & Drop is with ImageList APIs:
    WM_LBUTTONDOWN : ImageList_BeginDrag, SetCapture, ImageList_DragEnter
    WM_MOUSEMOVE : ImageList_DragMove
    WM_LBUTTONUP : ImageList_EndDrag, ReleaseCapture
    WM_PAINT : ImageList_Draw

    Quick test :

    168351-dragdrop.gif


0 additional answers

Sort by: Most helpful