Thread: Outputting highlighted text?

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Farther than you think
    Posts
    11

    Outputting highlighted text?

    Hello,

    I've noticed that a lot of text-based programs allow you to use the arrow keys to move up and down a list of options. The currently selected option would be highlighted, ie, the text background would be white, and the foreground black, instead of the other way around as usual.

    How would I go about printing highlighted text in C? Thanks.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    You would need to make use of an console library to do this. A popular one is ncurses. ncurses only works on Linux/Unix, so if you are using Windows, you would need something else.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Or you could write for ncurses, and use an implementation of ncurses on Windows, such as PDCurses. (One of many, google "windows ncurses" for more...)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    Mar 2006
    Location
    Farther than you think
    Posts
    11
    Lol, yeah, I probably should've said that I'm working under Windows.

  5. #5
    Registered User
    Join Date
    Mar 2006
    Location
    Farther than you think
    Posts
    11
    In any case, I've found out how to do this. The MSDN library has a bunch of useful stuff listed. Functions like SetConsoleTextAttribute() are exactly what I'm looking for. Apparently everything I need is in windows.h. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting Edit Control Text
    By yoonkwun in forum Windows Programming
    Replies: 2
    Last Post: 07-12-2009, 08:48 AM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  3. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  4. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  5. highlighted text
    By Unregistered in forum Linux Programming
    Replies: 2
    Last Post: 03-07-2002, 11:20 PM