Click here to Skip to main content
15,892,746 members
Articles / Desktop Programming / Win32

How to Create an Object Oriented Win32 Console Application

Rate me:
Please Sign up or sign in to vote.
2.67/5 (10 votes)
29 May 2010CPOL2 min read 43.9K   909   19  
How to create an object oriented Win32 Console application

// *********************************************************************
// *     This software is made available only to individuals and only  *
// *     for educational purposes. Any and all commercial use is       *
// *     stricly prohibited.                                           *
// *********************************************************************
//**********************************************************************
//* Disclaimer: Any borrowed code used in this                         *
//*             program is the property of the                         *
//*             code originator. credit to them.                       *
//*                                                                    *
//*                                                                    *
//*   Unfinished                                                       *
//*   WARNING:                                                         *
 //*                                                                    *
//*                                                                    *
//**********************************************************************

#ifndef  ExampleTEXTMODE_H
#define ExampleTEXTMODE_H

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <iostream.h>
#include <math.h>
#include <fstream.h>

class cExampleTextMode
{
	public:

		cExampleTextMode(){}
		cExampleTextMode(int startUp){}
		~cExampleTextMode(){}

		int temp,kbChar;


		/*
		void getKey();
		void gotoxy(int x, int y);
		void setcolor(WORD color);
		void textColor(unsigned char fColor,unsigned char bColor);
		void clrscr();
		void delay(int milliseconds);
		void txtPlot(int x, int y,int color);
		void txtLine( int xx1, int yy1, int xx2, int yy2 ,int color);


		*/
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void gotoxy(int x, int y)
		{
			COORD coord;
			coord.X = x; coord.Y = y;
			SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
			return;
		}
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void setcolor(WORD color)
		{
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),color);
			return;
		}
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void clrscr()
		{
			COORD coordScreen = { 0, 0 };
			DWORD cCharsWritten;
			CONSOLE_SCREEN_BUFFER_INFO csbi;
			DWORD dwConSize;
			HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

			GetConsoleScreenBufferInfo(hConsole, &csbi);
			dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
			FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
			GetConsoleScreenBufferInfo(hConsole, &csbi);
			FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
			SetConsoleCursorPosition(hConsole, coordScreen);
			return;
		}
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void box(unsigned x,unsigned y,unsigned sx,unsigned sy,unsigned char col,unsigned char col2,char text_[])
		{  unsigned i,j,m;
			{

			   m=(sx-x);                       //differential
			   j=m/8;                          //adjust
			   j=j-1;                          //more adjustment
			   gotoxy(x,y);cprintf("�");       //Top left corner of box
			   gotoxy(sx,y);cprintf("�");      //Top right corner of box
			   gotoxy(x,sy);cprintf("�");      //Bottom left corner of box
			   gotoxy(sx,sy);cprintf("�");     //Bottom right corner of box

			   for (i=x+1;i<sx;i++)
			   {
				  gotoxy(i,y);cprintf("�");     // Top horizontol line
				  gotoxy(i,sy);cprintf("�");    // Bottom Horizontal line
			   }

			   for (i=y+1;i<sy;i++)
			   {
				  gotoxy(x,i);cprintf("�");     //Left Vertical line
				  gotoxy(sx,i);cprintf("�");    //Right Vertical Line
			   }

				  gotoxy(x+j,y);cprintf(text_); //put Title
				  gotoxy(1,24);
			}
		}
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void clrbox(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char bkcol)
		{
			int x,y;
			setcolor(bkcol);                       //Set to color bkcol

			for (y=y1;y<y2;y++)                    //Fill Y Region Loop
			{
				for (x=x1;x<x2;x++)               //Fill X region Loop
				{
				  gotoxy(x,y);cprintf(" ");       //Draw Solid space
				}
			}
		}
		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************

		void putbox(unsigned x,unsigned y,unsigned sx,unsigned sy,
				 unsigned char col, unsigned char col2,unsigned char bkcol,char text_[])
		{
			clrbox(x,y,sx,sy,bkcol);
			box(x,y,sx,sy,col,col2,text_);
		}

		//*****************************************************************************
		//*                                                                           *
		//*****************************************************************************


		void txtPlot( unsigned char x, unsigned char y, unsigned char Color)
		{
				setcolor(Color);
				gotoxy(x,y);cprintf("�");
		}

		void delay(unsigned int milliseconds)
		{
			clock_t ticks1, ticks2;
			unsigned int tic1=0,tic2=0,tick=0;

			ticks1=clock();
			while(tick<milliseconds)
			{
				ticks2=clock();
				tic1=ticks2/CLOCKS_PER_SEC-ticks1;
				tic2=ticks1/CLOCKS_PER_SEC;
				tick=ticks2-ticks1;
			}
			ticks2=clock();
		}

};


#endif ExampleTextMode_H

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Sweden Sweden
About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

Comments and Discussions