Hey there, I'm new to both this forum and C++
I've been following this tutorial and up until now everything went flawless,
but all of a sudden I had to use a lot of windows.h functions which are quite
a pain in the ass.
I have listed parts of some of my files, ConLib.h, ConLib.cpp and game.cpp
The function WriteLine is grinding my gears, the only output I get are question marks :/
(The program is a consoleprogram)
Header file containing declaration
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
// ConLib.h
// Avoiding redefenition
#pragma once
// including windows header file
#include <Windows.h>
// ConLib color codes
enum ConColor
{
ConRed = 1,
ConGreen = 2,
ConBlue = 4
};
// ConLib controll class
class ConLib
{
// Handling screen and keyboard handles
HANDLE m_Screen;
HANDLE m_Keyboard;
// COlor Attributes
WORD m_TextColor;
WORD m_BackgroundColor;
public:
// con- and destructor
ConLib();
~ConLib();
// Setting Attributes
void SetBackgroundColor(WORD Color);
void SetTextColor (WORD Color);
void SetPosition (COORD Position);
// Output methods
void Clear();
void OutputString(char * String);
// Input methods
void Read (char * Buffer, DWORD BufferSize);
int GetKey();
};
|
__
source file where WriteConsole is being covered
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// ConLib.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "targetver.h"
#include "ConLib.h"
...
m_Screen = GetStdHandle (STD_OUTPUT_HANDLE);
// Sending string to screen
void ConLib::OutputString (char * String)
{
DWORD Written;
WriteConsole (m_Screen, String, strlen (String), &Written, NULL);
}
|
___
Example of usage
#include "stdafx.h"
// including game header file
#include "Game.h"
...
m_Console->OutputString("\tWelcome to Monster 1.0\n\n");
...