Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coloring Common Controls Like CEdit, CStatic in a SDI or MDI

Status
Not open for further replies.

PolarFreeze

Programmer
Aug 27, 2001
3
US
I am putting controls like CEdit and CStatic in a SDI and i am wanting to change the background color of the control.

I am able to do it in a dialog through the WM_OnCtlColor message but the document view doesn't seam to handle it.

Any help is be very welcomed.
 
Derive your classes from CEdit or CStatic

To change the color of a control in a document/view MFC application you will have to override the OnPaint method of your CEdit derived class with code like that:(put it AFTER the call to CEdit::OnPaint())

//in the CEdit derived class header
private:
CBrush brBack; //brBack

//in constructor put the line
brBack.CreateSolidBrush(RGB(x,y,z));

//in OnPaint
//if you don't have a pDC(pointer to the DC) get one either with GetDC or CClientDC dc(this);

CBrush* pOldBrush = pDC->SelectObject(brBack);

... restore
pDC->SelectObject(brBack); s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
It doesn't work that way. But i did get it to work by deriving a CEdit class then calling the WM_CTL_Color message and then color.

But now when i do a SetWindowText to it the text is there it just doesn't show up. you have to select the text just so that you can see the text.

If anyone has away of fixing this please reply
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top