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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetTextColor

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I've seen some of these threads that say to use SetTextColor on changing the color of a static, but I have had no luck. It stays the same color no matter what I do. Some help on this matter would be greatly appreciative. Here is what I have so far.

error = SetTextColor((m_s_accserver.GetDC())->m_hDC, COLORREF(0x00FF0000));

Now, to me, this seems like it should work. I recall having to call somesort of CWin.UpdateWindow() or CWin.RedrawWindow() function to get one of my windows to display right. But this was a long time ago and I don't remember. What else do I need to do to get the static control to change color? Thanks for ya'lls help!

Niky Williams
NTS Marketing, Inc
 
What kind of Aplication you have? MFC or SDK?
(I mean the code above s take from a "case WM_PAINT: SetTextColor...")? s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Sorry, straight MFC. I don't wanna have to use the OnCtlColor() function...it would be way too tedious. I just need a way to quickly change the color. Thanks for your help!

Niky Williams
NTS Marketing, Inc
 
Then there are are a lot of problems with your code:
1. All the drawing code must be put in the OnDraw(or the OnPaint) method of the drawed element. (m_s_accserver in this case). You should have a code like:

if(this->m_xColorFlag)
clr=RGB(0,0x0F,0);
else if ....
clr=RGB(0,0xAF,0);
... (or a switch{})
pDC->SetTextColor(clr)
clr(COLORREF) and m_xColorFlag should be mebers of the class.

Then to change the color you should do from EVERY other method:
m_s_accserver->m_xColorFlag = myCOLORID;
m_s_accserver->InvalidateRect(NULL); //force redraw

Why?
Just think of what happens if a window is maximized over your control AFTER you have put the code:
error = SetTextColor((m_s_accserver.GetDC())->m_hDC, COLORREF(0x00FF0000)); in some method.
Hope I am clear enough.

Good luck,
s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Thanks for yer time..I'll give this a shot and see what happens.

Niky Williams
NTS Marketing, Inc
 
hello i am a begining programer and want to settextcolor on borland c++ 3.5. i no its a really old but still i cannot get it to work.i could use an example or something thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top