I am trying to draw a rectangle around the current cursor's position. It works when I move the mouse but the rectangle is disappeared when I stop moving the mouse.
Code:
---------
void CView1::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_mouse_tracking)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER;
tme.hwndTrack = this->m_hWnd;
tme.dwHoverTime = HOVER_DEFAULT;
if (::_TrackMouseEvent(&tme))
{
m_mouse_tracking = true;
// Draw the 1st rect
draw_rect_(m_pDC);
}
}
else
{
// Draw new rect and erase old rect
RedrawWindow(NULL, NULL, RDW_INVALIDATE);
draw_rect_(m_pDC);
}
}
void CView1::OnMouseHover(UINT nFlags, CPoint point)
{
m_mouse_tracking = false;
draw_rect_(m_pDC);
}
---------
Is there something wrong with my source code? Please, help me.
↧