Getting textcolor in conio.h to work with Win32

This is a discussion on Getting textcolor in conio.h to work with Win32 within the C Programming forums, part of the General Programming Boards category; Is there a way to get text color with Win32? You can't get it with textcolor in conio.h cuz it's ...

  1. #1
    Teenage Mutant Ninja Nerd MMD_Lynx's Avatar
    Join Date
    Aug 2004
    Posts
    65

    Getting textcolor in conio.h to work with Win32

    Is there a way to get text color with Win32? You can't get it with textcolor in conio.h cuz it's not compatible (for some reason )
    Stupid people are useful. You can make them do all the mindless tasks you are too lazy to do yourself.

    Sphynx cats are just bald and wrinkly, like old people, and we don't reject them.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Teenage Mutant Ninja Nerd MMD_Lynx's Avatar
    Join Date
    Aug 2004
    Posts
    65
    [sarcasm]oh that helps[/sarcasm]
    im still pretty much a beginner and need something pretty basic.

    EDIT:
    I checked out the FAQ and I guess that is the only way to do it. man...that smells.
    Last edited by MMD_Lynx; 09-01-2004 at 03:15 PM.
    Stupid people are useful. You can make them do all the mindless tasks you are too lazy to do yourself.

    Sphynx cats are just bald and wrinkly, like old people, and we don't reject them.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    conio.h was made for DOS (which doesnt run in a win32 enviroment). What you are looking for is a way to change the console text color.

    Check out the function SetConsoleTextAttribute(). You can do Google searches for code examples. Microsoft also has an example in the Console SDK.

  5. #5
    Helper
    Join Date
    Jun 2004
    Posts
    255
    Quote Originally Posted by MMD_Lynx
    Is there a way to get text color with Win32? You can't get it with textcolor in conio.h cuz it's not compatible (for some reason )
    There is a conio.c file offered with the Dev-C++ suite, that implements most of the conio function for Windows Console mode.
    Emmanuel Delahaye

    "C is a sharp tool"

  6. #6
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Try this function (don't forget to #include <windows.h>):

    Code:
    void setcolor(int fore, int back) {
      SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), fore + (back << 4));
    }
    I may have fore and back reversed but I don't remember since it's been a while since I used C and I don't have a way to test it.

    If I remember correctly, there should be a link to tutorials on using the console around here someplace.
    Last edited by Frobozz; 09-02-2004 at 01:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console program to Win32
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 02-25-2008, 11:46 AM
  2. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  3. If you are employed as a programmer, please look
    By Flood Fighter in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 09-28-2004, 02:35 AM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21