Jump to content

ANSI C coloring in Windows console


midnite
 Share

Recommended Posts

hi there,as mentioned in the topic, do anyone know how to display colored text in Windows XP console by C programming language?? please be noted that i want only the specific text be colored, NOT all the text. for exampleThis is the text to be highlighted.* in the console default, it is black background and white text.PS i found some methods in the web, but they work only in older platforms, not in XP.and it is:printf("This is the \x1b[31mtext\x1b[0m to be highlighted\n");Thanks very very much in advance !!

Link to comment
Share on other sites

This is not related to Web Development!!!

Link to comment
Share on other sites

This is not related to Web Development!!!
i understand. yet i can't find any better place to put it forward, and i always feel that plenty of elites here are willing to solve my little problem :)
Link to comment
Share on other sites

Oh! Sorry :) . I do know some C++ but not to advance.

Link to comment
Share on other sites

some sound advice http://mail.python.org/pipermail/tutor/200...ary/028474.htmlnot sure if it aplies to C aswell
It is possible but the user must load the ANSI.SYS device driver,usually in the CONFIG.SYS file. This allows you to embed standard ANSIcodes into your printstrings and thus change the colours(16 possible) and attributes(bold,underlineetc).In the days of Windows, editing CONFIG.SYS is probably too much to askusers so either you need to create an "installer" that does it forthemor write a simple GUI wrapper round your console mode code.Alan G
Oh!! Thanks very much!! That's exactly the stuff.i did find some other text on the web saying about the ANSI.SYS too. for example in wiki. yet i don't know how to deal with it -.-as it says "you need to create an "installer" that does it for them or write a simple GUI wrapper round your console mode code", but how to ??Thanks in advance for any suggestions or solutions :)
Link to comment
Share on other sites

if you had a ftp site you could wite in some code to download it and place it in the proper folder....it is fairly easy to create an installer in C# with VS but I don't have the slightest clue in C.What compiler/editor are you using?

Link to comment
Share on other sites

if you had a ftp site you could wite in some code to download it and place it in the proper folder....it is fairly easy to create an installer in C# with VS but I don't have the slightest clue in C.What compiler/editor are you using?
um um.. what if the user runs my program offline?i use DEV C++
By adding the following line to the CONFIG.NT file located in the Windows System32 directory, ANSI output from 16-bit legacy programs executing under the NTVDM will be interpreted:DEVICE=ANSI.SYS
in fact, is it that just adding that line into the user's computer as said in wiki, things will be done smoothly? i don't understand thoroughly what it says actually..if yes, is that similar to downloading a file and place it in to proper place (probably simpler?). i don't know both the methods neither -.-
Link to comment
Share on other sites

things solved by microsoft ultra clumsy functions,after several hours of researches and testing

#include <stdio.h>#include <windows.h>main(){  HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);  CONSOLE_SCREEN_BUFFER_INFO scrBufInfo;  WORD defaultAttr;  GetConsoleScreenBufferInfo(h, &scrBufInfo);  defaultAttr = scrBufInfo.wAttributes;   printf("this is the ");  SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);  printf("text");  SetConsoleTextAttribute(h, defaultAttr);  printf(" that i wanna to be in red\n");  system("PAUSE");}

LOL and i can go to bed n have a nice dream :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...