|
-
Nov 16th, 2000, 02:49 PM
#1
How do i set the text color and then have it stay that way when i leave the prog?
-
Nov 16th, 2000, 03:21 PM
#2
Frenzied Member
What do you mean when you leave the program. To simply change the color:
Code:
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, 03:43 PM
#3
-
Nov 21st, 2000, 02:41 PM
#4
-
Nov 21st, 2000, 06:31 PM
#5
Member
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Nov 21st, 2000, 08:09 PM
#6
Addicted Member
Code:
#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
Code:
#include <graphics.h>
but I dont think so.
-
Nov 21st, 2000, 09:45 PM
#7
The problem with that is that it doesnt stay that color after the program has ended.
-
Nov 22nd, 2000, 08:31 AM
#8
Addicted Member
What text are you wanting to color? The text in your app or like all dos text?
-
Nov 22nd, 2000, 09:59 AM
#9
-
Nov 22nd, 2000, 07:33 PM
#10
Member
The code to do all of dos (and this works in VC++) is
Code:
#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
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Nov 22nd, 2000, 08:57 PM
#11
Thats not dos, thats windows.
-
Nov 22nd, 2000, 09:28 PM
#12
Member
Umm.. Sorry thats a VC++ code only I just tried it
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Nov 23rd, 2000, 02:31 AM
#13
Its not that it will only work on VC++, itll work with borland too, the problem is that its Windows and not DOS.
-
Nov 23rd, 2000, 11:28 AM
#14
Member
No it is a windows console code
---~^ Absalom ^~---
There is nobody in the world who knows everything there is no one his/her workforce who knows everything what really makes the person smart is that he/she is not affraid to ask for help.
-
Nov 23rd, 2000, 01:45 PM
#15
Ok, now your just repeating what i said.
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
|