Win32 WM_MOUSEMOVE problem with redraw

Claudio La Rosa 21 Reputation points

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.

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,505 questions
{count} votes

Accepted answer
  1. Castorix31 81,341 Reputation points

    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 :


0 additional answers

Sort by: Most helpful