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....
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;
public:
ConLib();
~ConLib();
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.
Code:
ConLib::ConLib()
{
m_Screen = GetStdHandle (STD_OUTPUT_HANDLE);
m_Keyboard = GetStdHandle (STD_INPUT_HANDLE);
SetTextColor (ConRed | ConGreen | ConBlue);
SetBackgroundColor (0);
}
ConLib::~ConLib()
{
}
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...
Code:
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?