DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2008
    Posts
    37

    How to use Colours?

    Please checkout the attached image file. How can i use colours like it?
    Thanks in advance
    Attached Images

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    two easy methods:
    1- the header file: <graphics.h>
    OR
    2- the OLD turbo C for "C Language" compiler, you can use in it direct calls to manipulate with the user like setcolor() .. gotoxy() .. and even more ..

    *I think the OLD Borland can do that too ...(like Borland 5 but I'm not sure if there u need to include a special header file ..)
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    This little function should help you out..

    Remember to include <windows.h>

    Code:
    #define black 0
    #define dark_blue 1
    #define green 2
    #define cyan 3
    #define red 4
    #define dark_purple 5
    #define brown 6
    #define gray 7
    #define dark_gray 8
    #define blue 9
    #define neon_green 10
    #define light_blue 11
    #define light_red 12
    #define purple 13
    #define yellow 14
    #define white 15
    
    //actual function to set color
    void color(int color)
    {
       HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
       SetConsoleTextAttribute(hCon,color);
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    37
    I am using Dev C++
    Please explain the code as well, I m novice programmer

  5. #5
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Quote Originally Posted by manofspirit
    I am using Dev C++
    Please explain the code as well, I m novice programmer
    That is OK, it may be best you dont try and understand the "nuts and bolts" of this code then, however I have tried to explain it for you with the following piece of code with comments.

    Regards

    Code:
    #include <iostream>
    #include <windows.h>
    
    #define black 0
    #define dark_blue 1
    #define green 2
    #define cyan 3
    #define red 4
    #define dark_purple 5
    #define brown 6
    #define gray 7
    #define dark_gray 8
    #define blue 9
    #define neon_green 10
    #define light_blue 11
    #define light_red 12
    #define purple 13
    #define yellow 14
    #define white 15
    
    //actual function to set color
    void color(int color)
    {
       HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);			// A handle to the console screen buffer.
       SetConsoleTextAttribute(hCon,color);						// A function to set the attributes of 
    }															// characters written to the console screen buffer
    
    int main()
    {
    	color(4);												// Calling color function with parameter of 4 = RED
    	std::cout << "This text will be RED! " << "\n";			// Use standard output to screen, now text is RED
    	color(2);												// Calling color function with parameter of 2 = GREEN
    	std::cout << "This text will be GREEN! " << "\n";       // Use standard output to screen, now text is GREEN
    	std::cin.get();											// Used to keep console window open.
    	return 0;
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    37
    @Code Nerd
    Thanks a Lot :)
    Can u plz refer me some tutorials/books/links about window.h, As im interested to learn about it

  7. #7
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    Quote Originally Posted by manofspirit
    @Code Nerd
    Thanks a Lot :)
    Can u plz refer me some tutorials/books/links about window.h, As im interested to learn about it
    There isnt much to learn really, is it just like any other #include file that you may use!

    windows.h is a header file for accessing the Win32 API (Application Programming Interface)

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Windows.h is probably one of the most common includes in all of the C/C++ programming language.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. Unable to Unload and/or End Program Properly
    By JSThePatriot in forum VB Classic
    Replies: 8
    Last Post: 04-22-2007, 12:19 AM
  2. Replies: 3
    Last Post: 03-30-2007, 10:46 PM
  3. Copying RTF colours
    By Lithic in forum VB Classic
    Replies: 3
    Last Post: 02-28-2005, 06:14 PM
  4. Hyperlink colours?
    By JoJo in forum VB Classic
    Replies: 3
    Last Post: 07-10-2002, 07:28 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links