Problem with WriteConsoleOutput

Hi guys,

A quick question, but first here's the code...

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

#include <Windows.h>
#include <iostream>

const int WIDTH=50;
const int HEIGHT=20;

int main(void){
	char hold;

	HANDLE write_handle=GetStdHandle(STD_OUTPUT_HANDLE);

	SMALL_RECT window_size={0,0,WIDTH-1,HEIGHT-1};
	COORD screen_buffer={WIDTH,HEIGHT};

	SetConsoleWindowInfo(write_handle,TRUE,&window_size);
	SetConsoleScreenBufferSize(write_handle,screen_buffer);
	SetConsoleTitle("Test");

	//////////////////
	CHAR_INFO some_char;
	some_char.Char.AsciiChar='P';
	some_char.Attributes=FOREGROUND_BLUE | FOREGROUND_RED |
                          FOREGROUND_INTENSITY;
	SMALL_RECT window_buffer={0,0,WIDTH,HEIGHT};
	COORD char_buffer_size={1,1};
	COORD char_pos;
	char_pos.X=0;//problem here when >0
	char_pos.Y=0;//problem here when >0

	WriteConsoleOutput(write_handle, &some_char, char_buffer_size, char_pos, &window_buffer);

	std::cin>>hold;

	return 0;
}


When I use char_pos={0,0}; it prints the char to console, but when I use any other integers (within the window bounds of course) nothing prints to screen.

Can anyone identify why this simple program is not working for different char_pos coordinates?

Thanks,

Mike
WriteConsoleOutput:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404%28v=vs.85%29.aspx


The buffer you give it (ie: &some_char) is not supposed to be a single character, but is supposed to be a 2-dimentional array of characters.

The 'char_pos' you give it is telling it which position in that 2D array you are wanting to output. Since you are only giving it a single character, anything but the character at 0,0 will not print because it doesn't exist.
Topic archived. No new replies allowed.