Thread: Help with using header files

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50

    Can't get this color header to work

    Hi, I have a header file I found on this website I want to use to simplify using color.

    Code:
    /*
    *   Copyright (c) 2002
    *
    *   Made by Petter Strandmark ("Sang-drax")
    *   http://www.strandmark.com
    *   Needed for functionality : <windows.h>
    *
    */
    
    /*
    *  USAGE:
    *
    *  cout << RED << "This is red." << BLUE << "\nThis is blue.";
    *
    *
    */
    
    #ifndef COLOR_PETTER_H
    #define COLOR_PETTER_H
    
    
    //Retain ANSI/ISO Compability
    #ifdef WIN32
        #include <windows.h>
    #endif
    
    #include <iostream>
    
    
    namespace Petter
    {
        
        namespace
        {
            class Color
            {
                friend std::ostream& operator<<(std::ostream& stream,const Color& c);
    
            public:
                Color(unsigned short c): color(c) {}
                static bool IsAvailabe()
                {
                    #ifdef WIN32
                        return true;
                    #else
                        return false;
                    #endif   
                }
            //private:
                unsigned short color;
            };
    
            std::ostream& operator<<(std::ostream& stream,const Color& c)
            {
                stream.flush();
                #ifdef WIN32
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c.color);
                #endif
                stream.flush();
    
                return stream;
            }
    
            #ifdef WIN32
                const Color NORMAL  = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE;
                const Color WHITE   = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY;
                const Color RED     = FOREGROUND_RED|FOREGROUND_INTENSITY;
                const Color DKRED     = FOREGROUND_RED;
                const Color BLUE    = FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_INTENSITY;
                const Color DKBLUE    = FOREGROUND_BLUE|FOREGROUND_GREEN;
                const Color GREEN   = FOREGROUND_GREEN|FOREGROUND_INTENSITY;
                const Color DKGREEN   = FOREGROUND_GREEN;
                const Color YELLOW  = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;
                const Color BROWN   = FOREGROUND_RED|FOREGROUND_GREEN;
            #else
                const Color NORMAL  = 0;
                const Color WHITE   = 0;
                const Color RED     = 0;
                const Color DKRED     = 0;
                const Color BLUE    = 0;
                const Color DKBLUE    = 0;
                const Color GREEN   = 0;
                const Color DKGREEN   = 0;
                const Color YELLOW  = 0;
                const Color BROWN   = 0;
            #endif
        }
    
    }
    #endif //ifndef
    I'm using Dev-C++ 4.9.9.2, my question is, how do I go about turning this code into a header file? And how to I instalize it in my program?
    Last edited by Flakster; 09-21-2005 at 02:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM