Thread: How to blink text?

  1. #1
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20

    How to blink text?

    Does anyone know how to do this?

    and also how to change the font color?

    Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Depends on the system you are trying to blink text within. In old-times on a monochrome screen, you would set the top bit in the text colour attribute and it would automatically blink at approximately 2Hz.

    For more modern systems, you actually have to draw the text and then undraw it [or, if you use a VGA style text-screen, you could perhaps change the attribute to be "same text and background colour"].

    In a windowed environment, you'd definitely be drawing and erasing the text to make it blink.

    As to changing colour, that is the same concept - in VGA/CGA/MGA you can change the attribute that goes with each character, in Windowing mode, you'd be setting the colour before you draw the text.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    How do you draw and undraw it?

    Can you give me some example....

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, that again, depends on the environment you want to do it in.

    This will sort of work reasonably portable to a console type application - you may need to adjust the slowdown() numbers to make it right.
    Code:
    void slowdown(int count)
    {
        while(--count) {
            putchar(0);
        }
    }
    
    int main()
    {
        char *s ="Some text";
        int i;
        for(;;) {
            printf("%s", s);
            slowdown(1000);
            putchar('\r');
            for(i = 0; i < strlen(s); i++)
               putchar(' ');
            slowdown(1000);
        }
    }
    I haven't tested that. But anything more advanced would be dependant on the system it's implemented on.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Divine
    Join Date
    Oct 2007
    Location
    Earth(duh!)
    Posts
    20
    I've tested it. One error: 'strlen' : undeclared identifier.

    So, what should I do now?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You may need to #include <string.h> and <stdio.h> - the above code wasn't meant to be a "complete compilable file", but rather to show the essential bits.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM