Win32 Console app Problems...

This is a discussion on Win32 Console app Problems... within the C++ Programming forums, part of the General Programming Boards category; Hey guys, i was trying my hand at WIN32 Console apps before i move on to Windows programming, to get ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434

    Exclamation Win32 Console app Problems...

    Hey guys, i was trying my hand at WIN32 Console apps before i move on to Windows programming, to get more of a feel for some of <Windows.h> commands. Anyways, i was trying to make a program that makes colored text. The command i use is long and is annoying to write over and over again, so i was trying to incorporate it into a function, Here is the code...

    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    HANDLE hout=GetStdHandle(STD_OUTPUT_HANDLE);
    
    void red();
    
    int main()
    {
         char colortext[20];
         cout<<"text to write in red: ";
         cin.getline(colortext,20);
         red();
         cout<<"\n\n"<<colortext;
         cin.get();
         return 0;
    }
    
    void red()
    {
         GetConsoleTextAttribute(FOREGROUND_RED, hout);
    }
    Any ideas? Thanks guys!

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    You need to change your red function to this
    Code:
    void red()
    {
      
      SetConsoleTextAttribute(hout, FOREGROUND_RED);
    
    }
    Woop?

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You may be interested in Adrianxw's Win32 Console Tutorial.

  4. #4
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Thats where i leanred it! Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 10-30-2008, 03:52 PM
  2. Console app termination
    By C+/- in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2008, 11:29 AM
  3. Simple Win32 console app using 99% of CPU?
    By c_olin3404 in forum C++ Programming
    Replies: 5
    Last Post: 02-17-2005, 02:04 PM
  4. Problems with standard WIN32 Code
    By BruceLeroy in forum Windows Programming
    Replies: 6
    Last Post: 08-24-2004, 09:20 AM
  5. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21