c ++ win32从编辑框中隐藏(禁用)插入符号 [英] c++ win32 hide (disable) caret from an edit box

查看:29
本文介绍了c ++ win32从编辑框中隐藏(禁用)插入符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户可以从只读编辑框中选择文本,但他不会看到闪烁的插入符号.我已经能够使插入符号从编辑中消失,但它仍然可以看到一瞬间.

I'm trying to make it so that a user can select text from a read-only edit box, but he won't see the blinking caret. I've been able to make the caret disappear from the edit, but it can still be seen for an instant.

这是我的子类代码:

LRESULT CALLBACK UserInfoProc (HWND hUserInfoWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{

    HideCaret(hUserInfoWnd);

    return DefSubclassProc(hUserInfoWnd, uMsg, wParam, lParam);

}

这是一小段代码,我知道,但它几乎可以完成我想要的.

It's a modest bit of code, I know, but it almost does what I want.

那么会发生什么,当我单击编辑时,可以看到插入符号一瞬间(50 毫秒?).我希望它根本不出现.我怎样才能做到这一点?我希望用户仍然能够从编辑中选择文本.

So what happens is, that when I click the edit, the caret can be seen for an instant (50ms?). I want that it doesn't appear at all. How can I do this? I want the user to still be able to select the text from the edit.

推荐答案

您可以尝试将 HideCaret() 调用移动到 DefSubclassProc() 之后,因为在如果一条消息触发插入符,那么直到 下一条 消息才会再次隐藏它.

You could try moving the HideCaret() call to after the DefSubclassProc(), since at the moment if a message triggers the caret it won't be until the next message that it's hidden again.

此外,我猜想触发插入符号显示的唯一消息是 WM_SETFOCUS,因此您可能只想测试该消息.例如,

Also, I would guess that the only message that triggers the caret to be shown is WM_SETFOCUS, so you may want to test for that message only. For example,

LRESULT CALLBACK UserInfoProc (HWND hUserInfoWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
    LRESULT lRes = DefSubclassProc(hUserInfoWnd, uMsg, wParam, lParam);
    if (uMsg == WM_SETFOCUS) // maybe?
        HideCaret(hUserInfoWnd);
    return lRes;
}

这篇关于c ++ win32从编辑框中隐藏(禁用)插入符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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