I used the TOM (Text Object Model) interfaces of the rich edit control to determine if the mouse was over green text to avoid changing the control's selection.
Add
#include <RichOle.h>
#include <TOM.h>
Then in the declaration of CMyRichEditCtrl -
....rest of class
public:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
virtual void PreSubclassWindow();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
private:
CComPtr<ITextDocument> m_pDoc;
HCURSOR m_hand;
bool m_bOverGreen{ false };
};
In the definition of CMyRichEditCtrl class -
void CMyRichEditCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRichEditCtrl::OnMouseMove(nFlags, point);
ClientToScreen(&point);
CComPtr<ITextRange> pCursor;
m_bOverGreen = false;
if ( SUCCEEDED(m_pDoc->RangeFromPoint(point.x, point.y, &pCursor)))
{
CComPtr<ITextFont> pFont;
if (SUCCEEDED(pCursor->GetFont(&pFont)))
{
long clr;
if (SUCCEEDED(pFont->GetForeColor(&clr)))
m_bOverGreen = clr == RGB(0, 255, 0);
}
}
}
void CMyRichEditCtrl::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CComPtr<IRichEditOle> pOle;
pOle.Attach(GetIRichEditOle());
ASSERT(pOle);
pOle.QueryInterface(&m_pDoc);
CRichEditCtrl::PreSubclassWindow();
}
BOOL CMyRichEditCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// TODO: Add your message handler code here and/or call default
if (m_bOverGreen)
{
SetCursor(m_hand);
return TRUE;
}
else
return CRichEditCtrl::OnSetCursor(pWnd, nHitTest, message);
}