textcolor/textattr in C++ problem

Hi all! my first post:-)

Well, I use borland compiler now, but if I need to use Dev-cpp to solve this problem, its fine with me.
I use cmd.exe on Windows XP Prof.

My problem is: I want to use the textattr() function of conio.h.. I maked a sample for you, but now I see that I cant get any colors too!

#include <stdio.h>
#include <iostream>
#include <conio.h>
//this should be enough I guess

using namespace std;

string a;

int main()
{
clrscr();
textcolor(2);
gotoxy(3,3);
textattr(4);
cout << "This should be underlined?";
cout << endl;
cout << "Wanna end this program? Press a key (Y) and then press enter..";
cin >> a;
}


But both, textcolor, and textattr doesnt work.. When I do textcolor([LIGHT]GREEN)
so, light and without light, it still doesnt work..

but functions, which can be found in conio.h, like clrscr() which clears the screen and gotoxy(3,3) which sets text on coords 3,3 works fine!!!
I think this is very strange..
I just want to make a 'input'-field, this was a class I wanted to make..
so it would look like: _______
and then if u enter on it something, the text self would be underlined too..

With such inputs I wanted to make a program, but it seems hard to just make text underlined:S

please, need some help! btw I am new to C++, but I know the basics..
If I remember right the text attribute functions in conio.h don't work on Win32. (I could be wrong though.)

You can use SetConsoleTextAttribute() (#include <windows.h>) to mess with attributes. They have the same bitvalues as in DOS (conio.h). The special bits are always set to "intensity" though, so you won't get underlined, you'll get bright green text.

MSDN Console Functions Reference
http://msdn.microsoft.com/en-us/library/ms682073(VS.85).aspx

The other option would be to simply ditch conio.h and use the Curses library.
http://www.cplusplus.com/forum/beginner/3637/page1.html#msg15565

Hope this helps.
Kk, thanks! But the weird thing is, that it worked, yesterday! But when I made modifications etc, and then when I started to make a new fresh program, it didnt work:S

the textattr() never worked, but if I did: textattr(2) it gave uhm darkblue (could be textattr(1) too)
and when I did textcolor(2 (or 1)), it gave same colors..
So i made a for-loop, with textcolor(i).. and textattr(i)
they both gave same colors, and after a while the background changed too!

Maybe you know now a bit more about my problem? pff I just wanted to have something underlined:S Is it that hard?!
Underlined: you can't without some work.

Method one: create a new font that you use in your console program.
Advantages: easier to use, stuff looks exactly like you want it to
Disadvantages: requires special handling before starting your actual application

Method two: draw on the window's DC directly
Advantages: relatively simple to do, requires no special handling
Disadvantages: you must use the Console event subsystem to keep the underlined text underlined if the user scrolls the window around, or you must resize the window buffer so that scrolling is not possible, requires direct GDI handling

Does it have to be underlined? Won't "bold" or some other color do?
IT WORKS! (sorry, not the solution/workaround Duoas gave me:P)

YAY, well, now you wanna know how huh?

Well, you need to make a file in your libraryfolder: called "Console.h".
Then paste this text in it: http://svn.kju-app.org/trunk/qemu/qemu/console.h
(You can download it too! Doesnt matter how..)

Well, then you can do colors in all kinds, try this:


#include <iostream>
#include <stdio.h>
#include "Console.h"

using namespace std;

int main(){
namespace con = JadedHoboConsole;
cout << con::clr;
cout << con::fg_green << con::bg_black << "Hello Green World!";
}



---------------------EXTRA------------------------:


well, then download my header: jetibest_objects.h

include it and you will be able to:
call: int puttext_xy(int x, int y, string text)
so you can put text on a x,y location

call: string select_option(string arr[], int x, int y, int aantal)
array, needs to have the buttonvalues with their actions
x,y is location
aantal=dutch for count. so how much buttons the array contains..

call: string textarea(int left, int top, int cols, int rows, string id, string text)
with that you make a textarea!
id is id, text is innerText, rows cols etc is width height.. left and top is x,y coords..

If you are interested, mail me on jeti2121@hotmail.com and ask me to mail it you!
Last edited on
Just so you all know, QEMU is a virtual machine (processor emulator).
Read more here
http://en.wikipedia.org/wiki/QEMU
and here
http://bellard.org/qemu/
Topic archived. No new replies allowed.