Some Problems about wm_ctlcoloredit Processing

Source: Internet
Author: User

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 @

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.