PDA

Click to See Complete Forum and Search --> : Text color


Nov 16th, 2000, 01:49 PM
How do i set the text color and then have it stay that way when i leave the prog?

Vlatko
Nov 16th, 2000, 02:21 PM
What do you mean when you leave the program. To simply change the color:


3.2.7. How do I change the background/text color of an EDIT control?

This can easily be accomplished by handling (NOT sending) the messages WM_CTLCOLOREDIT and WM_CTLCOLORSTATIC. Why the STATIC one? Well if the edit control is disabled then it sends WM_CTLCOLORSTATIC instead, so you need to be aware of which you are going to use or both.

To change the background colour you return the handle to a brush, which windows will use to paint the background of the control. To change the text color, you can use SetTextColor() on the HDC which is passed to you in the wParam parameter. You may also want to use SetBkMode() to set the text drawing mode to TRANSPARENT, otherwise your background color won't show through if you are changing it.

For example, to make the background black, you would do:

case WM_CTLCOLOREDIT:
return (LRESULT)GetStockObject(BLACK_BRUSH);

If your edit control is disabled, substitute WM_CTLCOLORSTATIC for WM_CTLCOLOREDIT.

But if your background is black, you probably don't want your text to be black. So we'll make it white:

case WM_CTLCOLOREDIT:
SetBkMode((HDC)wParam, TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255, 255, 255));
return (LRESULT)GetStockObject(BLACK_BRUSH);

If you only want to change the color for a single control, you can match the ID of the control you want to change to the ID of the hwnd you get in lParam:

case WM_CTLCOLOREDIT:
if(IDC_OF_THE_CONTROL == GetDlgCtrlID((HWND)lParam)){
SetBkMode((HDC)wParam), TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255, 255, 255));
return (LRESULT)GetStockObject(BLACK_BRUSH);
}
break;

If you haven't guessed by now, you can also use this to change the colors of STATIC controls, and a few others. (look up the WM_CTLCOLOR* messages in MSDN)

Nov 16th, 2000, 02:43 PM
I meant dos.

Nov 21st, 2000, 01:41 PM
Anyone?

absalom
Nov 21st, 2000, 05:31 PM
Please anyone

Stephen Bazemore
Nov 21st, 2000, 07:09 PM
#include <conio.h>
#include <string.h>

void keypress();

void main()
{

clrscr();
keypress();

}

void keypress()
{
textcolor(14);
gotoxy(35,13);
cprintf("Text color is yellow?");
getch();
}



Compile in Borland, for some reason it vc++ doesnt come with any graphics libraries. so you'll have to get them from somewhere else, or just compile in borland. you may also have to include


#include <graphics.h>


but I dont think so.

Nov 21st, 2000, 08:45 PM
The problem with that is that it doesnt stay that color after the program has ended.

Stephen Bazemore
Nov 22nd, 2000, 07:31 AM
What text are you wanting to color? The text in your app or like all dos text?

Nov 22nd, 2000, 08:59 AM
All of dos.

absalom
Nov 22nd, 2000, 06:33 PM
The code to do all of dos (and this works in VC++) is


#include <windows.h>
#include <string>
#include <iostream>
#include <wincon.h>
int main()
{
HANDLE hout;
DWORD ret;
hout=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hout, FOREGROUND_RED|BACKGROUND_GREEN);
cout << "Your Message here" << endl;
WriteConsole(hout,std.c_str(),std.size(),&ret,NULL);
}


you can find the different color codes in wincon.h

Nov 22nd, 2000, 07:57 PM
Thats not dos, thats windows.

absalom
Nov 22nd, 2000, 08:28 PM
Umm.. Sorry thats a VC++ code only I just tried it

Nov 23rd, 2000, 01:31 AM
Its not that it will only work on VC++, itll work with borland too, the problem is that its Windows and not DOS.

absalom
Nov 23rd, 2000, 10:28 AM
No it is a windows console code

Nov 23rd, 2000, 12:45 PM
Ok, now your just repeating what i said.