|
-
November 15th, 2003, 12:41 AM
#1
Why the text color doesn't change?
switch(message){
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
crOld = SetTextColor(hdc, (COLORREF)0x000000FF);
if(crOld == CLR_INVALID) MessageBox(hwnd, "SetTextColor", "Error", MB_OK);
TextOut(hdc, 0, 0, cBuffer, strlen(cBuffer));
EndPaint(hwnd, &ps);
return 0;
Hi, after using the function SetTextColor, why the color of the text remain unchanged? And would you please tell me how to change the size of the font? Thanks a lot!!!
-
November 15th, 2003, 03:24 AM
#2
Instead of
Code:
crOld = SetTextColor(hdc, (COLORREF)0x000000FF);
use something like
Code:
crOld = SetTextColor(hdc, RGB(255,0,0));
To draw text in a larger font, check this recent thread: http://www.codeguru.com/forum/showth...hreadid=272060
-
November 16th, 2003, 03:51 AM
#3
I have tried the method you mentioned, but the color remain unchanged. What's the matter?
-
November 16th, 2003, 08:26 AM
#4
Its WM_CTLCOLOR, not WM_PAINT.
-John
-
November 16th, 2003, 08:38 AM
#5
No, It should be possible with WM_PAINT and just change the color with SetTextColor to the color your want, but i really don't see anything wrong with the give code.
Of course you can use WM_CTLCOLOR, but then all text is in the given color. If you change the color in WM_PAINT, you can paint text in several different colors.
-
November 16th, 2003, 08:55 AM
#6
MSDN Says
A WM_CTLCOLOR message is sent to a window each time one of its child window controls (radio button, check box, scroll bar, and so forth) is to be painted on the screen. This message precedes the painting of the control. When it is desirable to change the appearance of controls, this can be done by processing the WM_CTLCOLOR message.
I dont know how you can do it in WM_PAINT. Even if you can, I'm sure its not the way you're thinking (or atleast as the way written by mctpursuer in WM_PAINT).
Of course you can use WM_CTLCOLOR, but then all text is in the given color. If you change the color in WM_PAINT, you can paint text in several different colors.
I dont know what you mean.
-John.
-
November 16th, 2003, 11:07 AM
#7
Originally posted by Indian_Techie
I dont know how you can do it in WM_PAINT. Even if you can, I'm sure its not the way you're thinking (or atleast as the way written by mctpursuer in WM_PAINT).
Well, to start with the original poster didn't mentioned it that he/she was trying to change the color of a certain control, so i just presumed that he/she was just drawing something to a certain window.
Now, apparently he/she just wants to draw text in a specific color, so he/she changes the textcolor of the DC to the desired color and then draws the text with TextOut. Quote from the MSDN: "The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color. "
So the text should appear in the color you've set with SetTextColor.
Now, if the original poster wants to change the text color of a certain *control*, then he/she should indeed be processing the WM_CTLCOLOR message.
I dont know what you mean.
-John.
When you use WM_CTLCOLOR, you can specify for a certain *control* that you want the text in that control to be red, but if the original poster wants to draw text on his/her window in *different* colors with some parts of the text in different colors (multicolor-text), then he/she should indeed be processing the WM_PAINT events and should use the SetTextColor function.
Now back to the original problem:
The code you've written is perfectly correct and i'm absolutely sure it works, so i guess the problems is somewhere else. If you code is not to big, you can post it, but please use the [ CODE]your code [ CODE] tags (without the blanks in the brackets!)
-
November 16th, 2003, 11:22 AM
#8
Well, to start with the original poster didn't mentioned it that he/she was trying to change the color of a certain control, so i just presumed that he/she was just drawing something to a certain window.
Now, apparently he/she just wants to draw text in a specific color, so he/she changes the textcolor of the DC to the desired color and then draws the text with TextOut. Quote from the MSDN: "The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color. "
So the text should appear in the color you've set with SetTextColor.
Oops! I'm sorry. I'ven't seen TextOut and trying to answer. Its my mistake.
-John.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|