I'm not sure if it's my code, although I feel fairly confident it
isn't, but SetConsoleScreenBufferSize() is failing with error 87,
which a quick browse of MSDN tells me is ERROR_INVALID_PARAMETER.
Could someone give this code the quick once over and tell me
where I'm going wrong, or simply how to get this to work?
---
module sample;
import std.c.windows.windows;
import std.conv;
import std.format;
import std.array;
import std.stdio;
alias HANDLE handle;
void main(){
auto buff =
CreateConsoleScreenBuffer(GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, null, CONSOLE_TEXTMODE_BUFFER,
null);
if( buff == INVALID_HANDLE_VALUE )
throw new Exception("Unable to create new screen buffer. Error:
" ~ text( GetLastError() ) );
COORD c = {60, 30};
// get the console window dims, to make sure this screen buffer
is as large or larger
CONSOLE_SCREEN_BUFFER_INFO* csbi = new
CONSOLE_SCREEN_BUFFER_INFO;
GetConsoleScreenBufferInfo( buff, csbi );
short width =
cast(short)(csbi.srWindow.Right-csbi.srWindow.Left);
short height =
cast(short)(csbi.srWindow.Bottom-csbi.srWindow.Top);
if(c.X<width)
c.X = width;
if(c.Y<height)
c.Y = height;
// set the screen buffer size !!!<= THIS IS WHAT DOESN'T WORK!
if(SetConsoleScreenBufferSize( buff, c ) == 0){
auto err = GetLastError();
throw new Exception("Unable to set buffer dimensions. Error: "
~ text(err) );
}
SetConsoleTextAttribute( buff,
FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|BACKGROUND_INTENSITY
);
c.X = 2; c.Y = 28;
SetConsoleCursorPosition( buff, c );
readln();
}
---
In advance, I really appreciate any help you can give me