In the process of encapsulating the system control for duilib, I encountered another problem in the text color/background color of the system edit control. Don't underestimate the message, and she will probably not make you feel the wish.
In fact, my goal is very simple:
1. Change text color
2. Change the text background color
The following lists some of my experiences that can be said to be a little strange.
Other background information is not automatically refreshed
Code:
static HBRUSH hbr;SetTextColor(HDC(wParam), RGB(0,255,0));if(!hbr) hbr = CreateSolidBrush(RGB(255,0,0));return LRESULT(hbr);
Effect:
Seemingly normal, but not actually normal
Code:
static HBRUSH hbr;SetTextColor(HDC(wParam), RGB(0,255,0));SetBkMode(HDC(wParam), TRANSPARENT);if(!hbr) hbr = CreateSolidBrush(RGB(255,0,0));return LRESULT(hbr);
Effect:
BUG:
Some text cannot be deleted when you try to delete it! (The cursor is moving, but the content is still there)
When the content increases, the scroll bar appears, and you try to drag the scroll bar:
Correct Handling Method
In fact, at first I confused the text color, text background, and background painter, so various Amazing effects would appear.
According to the answer of paint problem when handling wm_ctlcoloredit, you cannot use setbkmode to set transparency!
Set text color:
Settextcolor
Set the text background color:
Setbkcolor
Set the background paint color for areas without text:
Return the paint brush handle.
Test code:
static HBRUSH hbr;SetTextColor(HDC(wParam), RGB(0,255,0));SetBkColor(HDC(wParam), RGB(150,0,0));if(!hbr) hbr = CreateSolidBrush(RGB(150,0,0));return LRESULT(hbr);
Girl don't cry @ cnblogs.com/memset @