-
Setting Console Size
Hi all,
I'm looking for an alternative to using 'system ( "mode con:cols=50 lines=30" );' (those numbers don't have to be static, obviously), (looking for an alternative against the possibility that someone hacks into my computer, and makes a mode.bat file which does bad bad things to my computer!), to set the size (buffer and regular), of my console screen, so I turned to adrianxw, of course, and got lots of examples from here. When I saw the one about setting the screen buffer size, I thought it was great, but it says that the SetConsoleScreenBufferSize() function can't make the window any smaller, which is one of the possibilities I would like to cover. Can anyone suggest how I may go about making it smaller. Is there another function I should look into?
I've tried searching Google (albeit quickly), and anything I saw regarding the above problem was a warning about the function, and error checking - ie: if ( var < 0 ) cout<< "Cannot decrease size"; else blah blah ...
Ta very much.
-
-
Thanks prog-bman!! That's where I got all my info to date. The problem is he says - "If you try to make the screen buffer smaller than the window size, the call will fail.", using the SetConsoleScreenBufferSize function. I'm wondering if there's another function out there which can decrease, as well as increase the size.
I think I've twigged it ... if I first change the window size, and then change the buffer will it work?
-
-
No, Salem. Thanks for the link, I'm reading it at the moment. I'm basically using the code as the adrian guy put it up. I'll post my functions in a few mins when I finish them.
EDIT - Here are the functions -
Code:
Note, Error checking to come for these.
void ChangeScreenSize ( COORD NewSize )
{
HANDLE hOut = GetStdHandle( STD_OUTPUT_HANDLE );
SMALL_RECT DisplayArea = { 0, 0, 0, 0 };
CONSOLE_SCREEN_BUFFER_INFO SBInfo;
GetConsoleScreenBufferInfo( hOut, &SBInfo );
DisplayArea.Bottom = NewSize.Y;
DisplayArea.Right = NewSize.X;
SetConsoleWindowInfo( hOut, true, &DisplayArea );
}
void ChangeBuffSize ( COORD NewSize )
{
SetConsoleScreenBufferSize( GetStdHandle( STD_OUTPUT_HANDLE ), NewSize );
}
If I use them individually, they are ok, but in conjunction with eachother they don't seem to work. It seems ChangeBuffSize only increases, and ChangeScreenSize only decreases...