CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    WriteConsoleOutput

    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?


    Code:
    int main()
    {
    	Buffer buffer;
    
    	buffer.draw_intro();
    
    	_getch();
    	return 0;
    }
    Code:
    #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();
    }
    Last edited by Mybowlcut; May 15th, 2007 at 10:25 AM.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

  2. #2
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    1,569

    Re: WriteConsoleOutput

    I've found the problem... I think. I changed the red line to:

    Code:
    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:

    Code:
    buffer[x + y * SCREEN_WIDTH].Char.AsciiChar = '.';
    If anyone can confirm that my solution is right, I would really appreciate it.
    Good judgment is gained from experience. Experience is gained from bad judgment.
    Cosy Little Game | SDL | GM script | VLD | Syntax Hlt | Can you help me with my homework assignment?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured