c++ win32 hide (disable) caret from an edit box

ε祈祈猫儿з 提交于 2019-12-12 00:49:17

问题


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.

This is my code for the subclass:

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.

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.


回答1:


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.

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


来源:https://stackoverflow.com/questions/19849201/c-win32-hide-disable-caret-from-an-edit-box

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