Results 1 to 12 of 12

Thread: changing fore and backcolor in dos...

  1. #1

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134
    How do I change the fore and/or backcolor of the text that is printed using the printf() function?

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(handle,BACKGROUND_RED);
    Code:
    //extra info
    Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background: 
    FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    'HANDLE' undelcared identifier

  4. #4
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Code:
    #include <windows.h>
    ....
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(handle,BACKGROUND_RED);
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  5. #5
    Guest
    I just wanna say thats not dos, its a windows console.

  6. #6
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    error C2501: 'SetConsoleTextAttribute' : missing storage-class or type specifiers

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Code:
    #include<iostream.h>
    #include <windows.h>
    
    HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(handle,BACKGROUND_BLUE);
    SetConsoleTextAttribute(handle,FOREGROUND_RED && FOREGROUND_BLUE && FOREGROUND_GREEN && FOREGROUND_INTENSITY);
    
    	
    int main()
    {
    	int dummy;
    	int newString[101]
    
    	cout<<"Hello"<<endl;
    	cin.getline(newString,101,'\n')
    
    	cin>>dummy;
    	return 0;
    }

  8. #8
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Never mind...got it

  9. #9

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134

    Does this work in dos?

    Does that code works in dos mode? I mean when you run the program from DOS, not from a DOS prompt in windows...

  10. #10
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    No it would not because you are using the window.h, a windows only library, to set the DOS console colors, not the DOS colors. So you would have to be in windows for this to work.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  11. #11

    Thread Starter
    Addicted Member danielkw's Avatar
    Join Date
    Mar 2000
    Location
    Sweden
    Posts
    134

    but in dos then?

    But I want to know how to do it in DOS! It have to work in a way or another...
    It's done in almost every game written for DOS. Take Doom as an example... When you start doom.exe the program initializes everything (the WAD etc) etc... The first room is white colored text with red background that says "DOOM V1.1666" or whatever... How do I do that?

  12. #12
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024

    Unhappy

    I think that you will run into the problem that ChimpFace9000 is having. see:
    http://forums.vb-world.net/showthrea...threadid=48599
    sorry
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width