Hi,
The purpose of this procedure is to resize the console window and its buffer.
Unfortunately, I keep getting error 87 ("The parameter is incorrect.").
What am I doing wrong?
SetConsoleScreenBufferSize: The specified width and height cannot be less than the width and height of the console screen buffer's window.
To get around, you can shrink the window to a minimum before changing the buffer size
ChrisR wrote: Sun Oct 20, 2024 1:08 pmSetConsoleScreenBufferSize: The specified width and height cannot be less than the width and height of the console screen buffer's window.
To get around, you can shrink the window to a minimum before changing the buffer size
ChrisR wrote: Sun Oct 20, 2024 1:08 pmSetConsoleScreenBufferSize: The specified width and height cannot be less than the width and height of the console screen buffer's window.
To get around, you can shrink the window to a minimum before changing the buffer size
Procedure ResizeConsole(Cx, Cy)
If Cx <= 0 Or Cy <= 0 : ProcedureReturn : EndIf
Protected stdout = GetStdHandle_(#STD_OUTPUT_HANDLE)
; Set the window size
Protected rect.SMALL_RECT
rect\right = 1
rect\bottom = 1
; Resize the console window to minimal size
If (SetConsoleWindowInfo_(stdout, 1, @rect) = 0)
Debug "Error resizing console window: " + Str(GetLastError_())
EndIf
; Set the buffer size
If (SetConsoleScreenBufferSize_(stdout, Cx | (Cy << 16)) = 0)
Debug "Error setting buffer size: " + Str(GetLastError_())
ProcedureReturn ;Exit the procedure in case of an error.
EndIf
; Set the window size
rect\right = Cx - 1
rect\bottom = Cy - 1
; Resize the console window
If (SetConsoleWindowInfo_(stdout, 1, @rect) = 0)
Debug "Error resizing console window: " + Str(GetLastError_())
EndIf
EndProcedure
OpenConsole()
ResizeConsole(50,20)
Input()
ResizeConsole(70,20)
Input()
Hi ChrisR,
Your example works perfectly with the two values above, but if we specify ResizeConsole(77,99), the usual error 87 reappears.
Why?
I think I’ve found the problem this time: it’s caused by SetConsoleWindowInfo setting a value that’s too large for the window height, which leads to the error. The solution is to use GetConsoleScreenBufferInfo to ensure that these values are never exceeded. Thanks, ChrisR, both for the help you’ve given me and for your GUI editor, which has been useful to me on many occasions.