Results 1 to 3 of 3

Thread: textcolor

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    11
    I've been trying to move my old C++ console app to VC++ and encountered a problem with conio.h. Well, previously, I used an older borland C++ compiler(3.xx) and conio.h contained a function to change the console text color and the console background color. The VC++ version does not. Is this something specific to Borlands version?

    Also, is there some other library in VC++ that can do this? I searched the MSDN help files but couldn't find any.

    Here's the example function that utilizes the borland version:

    void SetColors(unsigned TxtColor, unsigned BkColor)
    {
    textcolor(TxtColor); textbackground(BkColor);
    }

    Thanks,
    Paul

  2. #2
    PowerPoster sail3005's Avatar
    Join Date
    Oct 2000
    Location
    Chicago, IL, USA
    Posts
    2,340
    Try this out. It uses windows.h:

    Code:
    #include <windows.h>
    
    int main(int argc, char* argv[])
    {
    HANDLE h = 	GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(h,FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_RED);
    	return 0;
    }

    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
    USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    11
    Thanks alot!!! Almost works, I'm running W2K so it could be something specific to it. The problem is the entire background isn't painted with the specified color, only where text is printed. The rest of the console is black. I'll tinker with it some more tomorrow.

    Thanks again,
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width