MFC CRichEditCtrl - Flickering while changing the cursor on the mouse move event

abc abc 351 Reputation points
2020-09-15T11:24:04.233+00:00

Hi,

In subclassed CRichEditCTrl, on mousemove event, I am changing curdor from default to hand cursor when moving mouse pointer over a particular format of text.

I am getting flickering when moving mouse over the text. That is the cursor is changed to hand cursor and back to default cursor.

void CEzMsgRichEditCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{

    POINTL ptl;
    ptl.x=point.x;
    ptl.y=point.y;
    long  index = (long)SendMessage(EM_CHARFROMPOS,(WPARAM)0,(LPARAM)&ptl);

   if(IsEmbedText(index))
   {
      if(!m_HandCursor) m_HandCursor = AfxGetApp()->LoadCursor(IDC_HAND_CURSOR);
      if(m_HandCursor)
      {
          m_DefaultCursor = SetCursor(m_HandCursor);
          m_bHandCursor = true;
      }
   }
   else if(m_bHandCursor)
   {
      SetCursor(m_DefaultCursor);
      m_bHandCursor = false;
   }
   CRichEditCtrl::OnMouseMove(nFlags, point);
}
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,753 questions
{count} votes

Accepted answer
  1. RLWA32 45,691 Reputation points
    2020-09-15T11:42:45.347+00:00

    The system redraws the cursor with the windows class cursor every time the mouse moves. Handle the WM_SETCURSOR message to use the hand cursor when appropriate.

    And a general observation - you can load the hand cursor once and save the handle in a member variable. You don't need to load it multiple times in the OnMouseMove handler. Use a different flag to determine when the hand cursor should be shown.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.