Hiding caret in RichEdit winapi

假如想象 提交于 2019-12-23 02:19:30

问题


I would like to hide a caret from a RichEdit(50W) with ES_READONLY style specified. It's pretty confusing for the user, when the caret is blinking and the user can't type.
I tried to hide the caret using HideCaret() function,
however it doesn't work for me with following code:

LRESULT CALLBACK ChatMessaegsSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) // Subclassed control
{
    LRESULT ret = CallWindowProc(WndProc_ChatMessages, hwnd, msg, wParam, lParam);
    switch(msg)
    {
    //Also tried with EN_SETFOCUS
    case WM_SETFOCUS:
    {
        ret = CallWindowProc(WndProc_ChatMessages, hwnd, msg, wParam, lParam);
        HideCaret(ChatMessages); //Returns 5 (Access denied.)
        break;
    }

    //According the documentation:
    //If your application calls HideCaret five times in a row, 
    //it must also call ShowCaret five times before the caret is displayed.
    case WM_KILLFOCUS: //The message is called when the RichEdit get focus, however nothing happens.
    {
        ret = CallWindowProc(WndProc_ChatMessages, hwnd, msg, wParam, lParam);
        ShowCaret(ChatMessages);
        break;
    }
    }
    return ret;
}

回答1:


Here is the solution:

LRESULT CALLBACK ChatMessaegsSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    LRESULT ret = CallWindowProc(WndProc_ChatMessages, hwnd, msg, wParam, lParam);
    switch(msg)
    {
    case WM_LBUTTONDOWN:
    {
        HideCaret(ChatMessages);
        break;
    }
    case WM_KILLFOCUS:
    {
        ShowCaret(ChatMessages);
        break;
    }
    }
    return ret;
}

NOTE this only works when user induces the focus with mouse. Therefore if anyone knows how to deal with it correctly, feel free to answer, I'll be glad.



来源:https://stackoverflow.com/questions/32896767/hiding-caret-in-richedit-winapi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!