How to change the selected text color of Edit control?

1
2
CEdit m_edMy;
m_edMy.SetWindowText("This is a control edit!");


When I drag cursor to mask the string, the default maybe blue(relate to OS).

Now I want to change the color to silver. How could I do?
I try to do it by the following, and tried some methods.But I got nothing.

1
2
3
4
class CSilverEdit : public CEdit
{
   //...
}


Anyway, thanks for any tip!
The following maybe of help as a starting point:

Using the Windows API directly
http://msdn.microsoft.com/en-us/library/bb432504%28VS.85%29.aspx

Using MFC:
http://msdn.microsoft.com/en-us/library/0wwk06hc%28VS.71%29.aspx
1
2
3
4
5
6
7
8
9
10
11
12
HBRUSH CSilverEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
{
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a non-NULL brush if the parent's handler should not be called
	CBrush br(RGB(0, 0, 0));
	pDC->SetBkColor(RGB(0, 0, 0));
	pDC->SetTextColor(RGB(0, 255, 0));
	//pDC->SetBkMode(TRANSPARENT);

	return HBRUSH(br);
}
I tried, but failed to changed the selected string color.
Topic archived. No new replies allowed.