简体   繁体   中英

How to disable "text-selection" cursor in RichEdit

I want to show standard "pointer" cursor instead of "text-selection cursor" (shown in the picture below) in RichEdit:

在此处输入图片说明

The only way I see now is to intercept WM_SETCURSOR message in my window, determine wether cursor is inside RichEdit control, and replace it with "normal" cursor. Besides it's not so cool, I want to keep a "hand" cursor, which appears when cursor points to a link.

Is there an easier method?

UPDATE: Some clarifications for comments:

  1. @Remy Lebeau. Actually I just want to display text with some formatting abilities: automatic words wrapping, different colors for some symbols inside the same text, hyperlinks, and may be - displaying images. And I want to get this text from the internet, display this text in a single control, also it's quitу comfortable to create such a text in RTF-editor, like WordPad. However the information shown in RichEdit is not intended to be edited or copied, and app design looks better without "text-selection" cursor. So, I think that RichEdit is what I need. But, of course, you can suggest something else.
  2. @Jeaninez. I have already set the ES_READONLY property, it does not affect neither cursor, nor selection (the latter I solved by intercepting the EN_SELCHANGE notifications).
  3. @Barmak Shemirani. Yes, I can process hyperlinks. Here is the code snippet I use now to handle cursor changing:
    // This method processes the WM_SETCURSOR message.
    LRESULT MainWindow::OnSetCursor(WPARAM wParam, LPARAM lParam) {
        auto h = (HWND)wParam;
        if (h == richEditHwnd) {
            return TRUE; // Prevents cursor changes by next processors
        }
        return DefWindowProc(mainWindowHandle, WM_SETCURSOR, wParam, lParam);
    }

To change the cursor to arrow, use ES_READONLY style, and handle WM_SETCURSOR .

SetCursor(hcursor) must be called each time:

hcursor = LoadCursor(nullptr, MAKEINTRESOURCE(IDC_ARROW));
...
case WM_SETCURSOR:
{
    if (hrichedit == (HWND)wparam) { SetCursor(hcursor); return TRUE; }
    break;
}

You are likely handling hyperlinks in WM_NOTIFY , you can change hcursor when cursor is over hyperlink.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM