Sonny
Sonny

Reputation: 182

Questions About Drawing without WM_PAINT Message

In MSDN, I read this

When drawing without using a WM_PAINT message, the application usually does not invalidate the window. Instead, it draws in such a fashion that it can easily restore the window and remove the drawing.

What does it means ? Becuase I wrote a GIS program, I want to implement the "Zoom In" feature, Mouse left button down and move the mouse to draw a rectangle, it's drawing a rectangle but the rectangle cover the map, first I think it is becuase the rectangle is not transparent, then I use AlphaBlend() to draw a transparent rectangle, it is the same. What should I do ?

draw a rectangle

LRESULT OnMouseMove(UINT nflags, CPoint point)
{
    if (m_bZoomInMode)
    {
        m_curScreenPoint.x = point.x;
        m_curScreenPoint.y = point.y;
        HDC hdc = GetDC();
        SelectObject(hdc, (HBRUSH)NULL_BRUSH);
        Rectangle(hdc, m_startScreenPoint.x, m_startScreenPoint.y, point.x, point.y);
        ReleaseDC(hdc);
        return 0;
    }
}

Upvotes: 0

Views: 994

Answers (1)

David Heffernan
David Heffernan

Reputation: 612963

To draw the rectangle, you can draw 4 lines. Or use a clear brush – that is use brush style BS_HOLLOW.

The other issue to solve is that as the user moves the mouse and the zoom rectangle will move and you will need to repaint what lies underneath. Do this as follows:

  1. Call InvalidateRect passing a rect for the previous location of the zoom rectangle.
  2. Call UpdateRect for force a paint cycle and paint what was under the previous zoom rectangle.
  3. Draw the new zoom rectangle.

Upvotes: 1

Related Questions