Click to See Complete Forum and Search --> : WriteConsoleOutput


Mybowlcut
May 15th, 2007, 10:21 AM
Hey. I'm using WriteConsoleOutput() to write a buffer of text/colour to a console application. I've made a Buffer class which is below, along with my main(). The problem IS, that it's displaying question marks instead of periods.. the line where I tried to do this is highlighted in red... I've tried stepping through it with the debugger but the Buffer instance's buffer variable (which is a CHAR_INFO struct declared in the blue line) has {UnicodeChar=L'쳌' AsciiChar='Ì' } for all of it's elements... that's where it should be a period. Can anyone tell me why this is playing up?


int main()
{
Buffer buffer;

buffer.draw_intro();

_getch();
return 0;
}

#include "Buffer.h"

Buffer::Buffer(ushort BUFFER_WIDTH, ushort BUFFER_HEIGHT)
{
buffer_size.X = BUFFER_WIDTH;
buffer_size.Y = BUFFER_HEIGHT;
output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
rect_info.X = 0;
rect_info.Y = 0;
}

bool Buffer::is_valid_draw(const COORD buffer_size)
{
if(buffer_size.X < SCREEN_WIDTH && buffer_size.Y < SCREEN_HEIGHT)
return true;
else
return false;
}

void Buffer::fill_buffer(const COORD buffer_size)
{
for(int y = 0; y < buffer_size.Y; y++)
{
for(int x = 0; x < buffer_size.X; x++)
{
buffer[x + y * SCREEN_WIDTH].Char.AsciiChar = '.';

buffer[x + y * SCREEN_WIDTH].Attributes = FOREGROUND_GREEN;
}
}
}

void Buffer::draw_intro()
{
SMALL_RECT draw_rect = {rect_info.X, rect_info.Y, rect_info.X + (SCREEN_WIDTH - 1), rect_info.Y + (SCREEN_HEIGHT - 1)};
COORD buffer_size = {SCREEN_WIDTH, SCREEN_HEIGHT};
COORD zero_zero = {0, 0};

fill_buffer(buffer_size);

WriteConsoleOutput(output_handle, buffer, buffer_size, zero_zero, &draw_rect);
_getch();
}

Mybowlcut
May 15th, 2007, 11:03 AM
I've found the problem... I think. I changed the red line to:

buffer[x + y * SCREEN_WIDTH].Char.UnicodeChar = '.';

Since in the project properties it's saying that the project is using the unicode character set... but the tutorial that I'm reading from says to have the line like:

buffer[x + y * SCREEN_WIDTH].Char.AsciiChar = '.';

If anyone can confirm that my solution is right, I would really appreciate it.