I'm doing some code in pascal using lazarus IDE v1.8.4, as the question says I need to be able to edit the console size in the code, I also preferably need to get the max possible console width they can have. If you do know how please also let me know the uses you.. used. Thanks!
Assuming you're targeting Windows:
Use GetLargestConsoleWindowSize
to retrieve the largest possible console size depending on the console font and display settings,
Use SetConsoleScreenBufferSize
to set the console screen buffer to the largest possible size,
Use SetConsoleWindowInfo
to set the size and position of the console's window, so that no scrollbars would be visible by default etc..
At this point the console's window should be positioned as you've set. With my tests, however, while the window complies with the sizing request, the position is ignored.
In that case use any API function to move the window, the below examples uses SetWindowPos
. I had to declare GetConsoleWindow
as it was not declared in Lazarus 1.6.
program Project1;
{$APPTYPE CONSOLE}
uses
windows;
function GetConsoleWindow: HWND; stdcall external 'kernel32';
var
Con: THandle;
Size: TCoord;
Rect: TSmallRect;
Wnd: HWND;
begin
Con := GetStdHandle(STD_OUTPUT_HANDLE);
Size := GetLargestConsoleWindowSize(Con);
SetConsoleScreenBufferSize(Con, Size);
Rect.Left := -10;
Rect.Top := -10;
Rect.Right := Size.X - 11;
Rect.Bottom := Size.Y - 11;
SetConsoleWindowInfo(Con, True, Rect);
Wnd := GetConsoleWindow;
SetWindowPos(Wnd, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
Readln;
end.
And don't forget to add error checking.