Question

I have created edit box using Win32 C++. I have subclassed it and overridden OnPaint menthod in which I am filling it with some background color.

Now if I enter some text I am not able to see any text but I can see cursor moving.

If I dont put any background color I can see text in edit box.

Any idea why I am not getting text with background color?

Was it helpful?

Solution

You are not supposed to handle WM_PAINT for the edit control. Here you are just trying to fill the background color, but in the process you are not allowing the original edit control procedure to paint the content, and in this case it is the text you entered. The cursor will be visible because it is shown using ShowCaret function.

So if you want to just change the background color of the edit control, handle WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC in the parent window and return the brush. Refer http://msdn.microsoft.com/en-us/library/windows/desktop/bb761691%28v=vs.85%29.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top