Thread: Example from book, don't understand.

  1. #1
    Join Date
    Aug 2003

    Example from book, don't understand.

    I am doing the 'building monster' example from the "Game Programming All in One" and there is something I dont quite understand from the code written. I have re-written the entire thing by hand and it works fine but there are still a few peices of code that I don't know why it works. For Example the author uses code that seemingly is not declared, (has no type and no declaration) it is just used. Here is a small part of the code....
    //ConLib Class
    enum ConColor
         ConRed = 1, 
         ConGreen = 2,
         ConBlue = 4
    class ConLib
          HANDLE m_screen;
          HANDLE m_keyboard;
          WORD   m_TextColor;
          WORD   m_BackgroundColor;
                 void SetBackgroundColor (WORD Color);
                 void SetTextColor (WORD Color);
                 void SetTitle (char * Title);
                 void SetPosision (COORD Position);
                 void Clear (void);
                 void OutputString (char * String);
                 void Read (char * Buffer, DWORD BufferSize);
                 int GetKey (void);
    I understand the ConLib() class above.
     m_Screen = GetStdHandle (STD_OUTPUT_HANDLE);
     m_Keyboard = GetStdHandle (STD_INPUT_HANDLE);
     SetTextColor (ConRed | ConGreen | ConBlue);
     SetBackgroundColor (0);
    void ConLib::SetBackgroundColor (WORD Color)
         m_BackgroundColor = 0;
         if (Color & ConRed)
            m_BackgroundColor |= BACKGROUND_RED;
         if (Color & ConGreen)
            m_BackgroundColor |= BACKGROUND_GREEN;
         if (Color & ConBlue)
            m_BackgroundColor |= BACKGROUND_BLUE;
         SetConsoleTextAttribute (m_Screen, m_TextColor | m_BackgroundColor);
    The part in bold is what I don't understand. It is not defined anywhere else in the entire program, the author just uses it here and in many other places. It goes into it talking about how its defined...
    BOOL SetConsoleTextAttribute (HANDLE hConsoleOutput, WORDwAttributes);
    and then goes on describing the paramaters. What I don't understand is that the code, used in the class, does not contain the type BOOL but it works. I don't know if I am asking this the right way. I just don't understand cause it looks like a function call with no type and no declaration. Why does this work and not cause errors?
    Knowledge is power and I want it all


  2. #2
    Registered User
    Join Date
    Aug 2005
    its a win32 api function, declared in windows.h

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a phone book program
    By mackieinva in forum C Programming
    Replies: 2
    Last Post: 09-19-2007, 06:31 AM
  2. URGENT: Help C
    By iamjimjohn in forum C Programming
    Replies: 16
    Last Post: 05-18-2007, 05:46 AM
  3. C++ Templates book discussion
    By manutd in forum C++ Programming
    Replies: 38
    Last Post: 01-18-2007, 02:56 PM
  4. recommendation for a good OOP book
    By Mario F. in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2006, 04:28 PM
  5. I"m selling a book...
    By St0rmTroop3er in forum Game Programming
    Replies: 2
    Last Post: 12-13-2003, 12:55 PM