none
show cursor position indicate line RRS feed

  • 问题

  • CPen penLine(PS_DOT,1,RGB(48,64,85)); CDC dc=CView::GetDC(); //get cursor position int cx=LOWORD(lParam); int cy=HIWORD(lParam); dc.SelectObject(penLine); POINT ptLine[2]; ptLine[0].x=ptLine[1].x=cx; ptLine[0].y=0; ptLine[1].y=500; ::Polyline(dc,ptLine,2);

    ReleaseDC(dc); penLine.DeleteObject();

    this is how i use in wm_mousemove  message , it did show the cursor position line , but it wasn't what i want, it showed each time i move cursor, and it did not erase the previous line . so How i should do to erase the previous line when move cursor? 
    • 已编辑 Rogerguo 2016年1月17日 8:08
    2016年1月17日 8:07

答案

  • You should add and draw on OnDraw/OnPaint() function. In WM_MOUSEMOVE handler function, you can save the current position into member variable, and then call InvalidateRect().
    For example:
    case WM_MOUSEMOVE:
    {
      m_pt.x = LOWORD(lParam);
      m_pt.y = HIWORD(lParam);
      InvalidateRect(hWnd, NULL, TRUE);
      UpdateWindow(hWnd);
    }
    break;

    case WM_PAINT:
    {
      // Draw
    }
    break;



    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    • 已标记为答案 Rogerguo 2016年1月20日 12:14
    2016年1月19日 3:27
    版主

全部回复

  • Hi Rogerguo,

    When move cursor you should redraw the line , you must to call the InvalidateRect function .

    The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn.for more information please look the link: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145002(v=vs.85).aspx

     

    Best Regards,

    Hart

    2016年1月18日 2:18
    版主
  • You should add and draw on OnDraw/OnPaint() function. In WM_MOUSEMOVE handler function, you can save the current position into member variable, and then call InvalidateRect().
    For example:
    case WM_MOUSEMOVE:
    {
      m_pt.x = LOWORD(lParam);
      m_pt.y = HIWORD(lParam);
      InvalidateRect(hWnd, NULL, TRUE);
      UpdateWindow(hWnd);
    }
    break;

    case WM_PAINT:
    {
      // Draw
    }
    break;



    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    • 已标记为答案 Rogerguo 2016年1月20日 12:14
    2016年1月19日 3:27
    版主