Program descr: Im trying to make a windows manager for windows I might draw in CONSOLE.
the plan is to draw manually windows in the console in an objectified way.
instead of drawing the windows using console coordinates I create a buffer then use writeConsoleOutput to write this buffer to the console. I have the following code which have this detail I dont understand. Im testing the code trying to output a grid of #'s (the symbol) but the output is the intended grid BUT with top left coordinate black (i.e coord 0,0 of the grid)
I suspect the vector class as the culprit, simply because if I call drawWin() at the end of win ctr ( after filling the buffer) the grid shows fines, maybe a vector is not adecuate for this case, if so I like to know why is giving this trouble, that is, if vector is indeed the trouble maker.
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>
#include <vector>
using namespace std;
//A 1-1 mapping from cells ti array
enum winStyle
{
warningsON, warningsOFF
};
const WORD Black = 0x0000;
const WORD fWhite = 0x0001 | 0x0002 | 0x0004;
const WORD bWhite = 0x0010 | 0x0020 | 0x0040;
class CUIelement
{};
class win
{
public:
win(COORD org , COORD size, winStyle ws);
~win();
void addElement(CUIelement x){}
const CHAR_INFO * getBuffer();
void drawWin(HANDLE hOut);
winStyle getWinStyle();
private:
CHAR_INFO * _buffer;
COORD _org;
COORD _size;
winStyle _ws;
};
HANDLE HOUT = GetStdHandle(STD_OUTPUT_HANDLE);
win::win(COORD org ,COORD size, winStyle ws): _org(org), _size(size),_ws(ws)
{
_buffer = new CHAR_INFO[size.X * size.Y];
for (int y = 0; y < size.Y ; ++y) {
for (int x = 0; x < size.X; ++x) {
_buffer[x+size.X*y].Char.AsciiChar = 0x23;
_buffer[x+size.X*y].Attributes = fWhite;
}
}
}
win::~win()
{
delete[] _buffer ;
}
winStyle win::getWinStyle(){ return _ws; }
void win::drawWin(HANDLE hOut)
{
COORD startWhereInBuffer = {0,0};
SMALL_RECT SBregion = {_org.X, _org.Y, _org.X + _size.X - 1 , _org.Y + _size.Y - 1 };
WriteConsoleOutput(hOut, _buffer, _size, startWhereInBuffer , &SBregion);
}
class SBman
{
public:
SBman( COORD _SBsize );
void addWindow(win w);
void drawScr();
private:
void setUpScr();
vector<win> vWin;
HANDLE _hOut ;
COORD _SBsize;
HWND _hWnd;
};
SBman::SBman(COORD SBsize): _hOut (GetStdHandle(STD_OUTPUT_HANDLE)),
_SBsize (SBsize), _hWnd(GetConsoleWindow())
{
setUpScr();
}
void SBman::addWindow(win w)
{
vWin.push_back(w);
}
void SBman::drawScr()
{
for(int i = 0 ; i < vWin.size() ; ++i )
{
//get window info
vWin[i].drawWin(_hOut);
}
}
void SBman::setUpScr()
{
SetConsoleScreenBufferSize(_hOut,_SBsize);
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(_hOut, &csbi);
SMALL_RECT winSize = {0,0,csbi.dwMaximumWindowSize.X-1,csbi.dwMaximumWindowSize.Y-1};
SetConsoleWindowInfo(_hOut,1,&winSize);
}
int main()
{
//make appropiate console
COORD size = {80,40};
SBman sb(size);
COORD wOrigin = {4,8};
// for(int j = 5 ; j < 40 ; ++j)
// for(int i = 5 ; i < 80 ; ++i)
//{
//create win
COORD wSize = {11,5};
win tmp(wOrigin, wSize, warningsOFF);
sb.addWindow(tmp);
sb.drawScr();
// }
}