在RichEdit Winapi中隐藏插入符号 [英] Hiding caret in RichEdit winapi

查看:153
本文介绍了在RichEdit Winapi中隐藏插入符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用指定的ES_READONLY样式从RichEdit(50W)中隐藏插入记号. 当插入符号闪烁且用户无法键入时,这对于用户来说非常令人困惑.
我尝试使用 HideCaret隐藏隐藏符号()函数,
但是,使用以下代码对我不起作用:

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;
}

推荐答案

以下是解决方法:

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.

这篇关于在RichEdit Winapi中隐藏插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆