Question

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.

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top