Reputation: 182
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 ?
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
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:
InvalidateRect
passing a rect for the previous location of the zoom rectangle.UpdateRect
for force a paint cycle and paint what was under the previous zoom rectangle.Upvotes: 1