DrawDragRect函数在窗口显示异常:
父窗口风格设置异常;
SetWindowLongPtr(m_hWnd,
GWL_EXSTYLE,
GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
去除这段代码就OK显示正常了
下面附上画选中矩形框的代码;
void OnLButtonDown(UINT nFlags, CPoint point) { SetCapture(); m_bDragging = true; m_lastPoint = point; CDC *pDC = GetDC(); CRect rect(point, point); pDC->DrawDragRect(&rect, CSize(1, 1), NULL, CSize(1, 1), NULL, NULL); m_lastRect = rect; ReleaseDC(pDC); } void OnMouseMove(UINT nFlags, CPoint point) { if (m_bDragging && GetCapture() == this) { CDC *pDC = GetDC(); CSize curSize(1,1), lastSize; CRect newRect(m_lastPoint, point); newRect.NormalizeRect(); lastSize.cx = 1; lastSize.cy = 1; pDC->DrawDragRect(newRect, curSize, m_lastRect, lastSize); ReleaseDC(pDC); m_lastRect = newRect; } } void OnLButtonUp(UINT nFlags, CPoint point) { if (m_bDragging && GetCapture() == this) { m_bDragging = false; CDC *pDC = GetDC(); CRect rect(0, 0, 0, 0); pDC->DrawDragRect(rect, CSize(1, 1), &m_lastRect, CSize(1, 1), NULL, NULL); ReleaseDC(pDC); //Invalidate(); ReleaseCapture(); } }