April 19, 2024, 04:57:10 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Console window resizing

Started by GWS, January 24, 2012, 11:43:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

Hi,

Here's how to resize the console window if you need more space ..  :)
This is a code example from Paul some years ago ..


'console window sizing example

TYPE smallrect
def left as WORD
def top as WORD
def right as WORD
def bottom as WORD
ENDTYPE

TYPE CONSOLE_INFO
    def dwSize as UINT 
    def dwCursorPosition as UINT
    def wAttributes as UINT
    def srWindow as INT64
    def dwMaximumWindowSize as UINT
ENDTYPE

DECLARE "kernel32",SetConsoleScreenBufferSize(hConsole as INT,size as UINT),INT
DECLARE "kernel32",GetConsoleScreenBufferInfo(hConsole as INT,info as CONSOLE_INFO),INT
DECLARE "kernel32",SetConsoleWindowInfo(hConsole as INT,bAbsolute as INT,size as smallrect),INT
DECLARE "kernel32",GetStdHandle(num as INT),INT
CONST STD_INPUT_HANDLE = -10
CONST STD_OUTPUT_HANDLE = -11
CONST STD_ERROR_HANDLE = -12

def handle as INT
def sm as smallrect
def co as UINT
def cinfo as CONSOLE_INFO
def newX,newY as INT
def oldX,oldY as INT
                         
' change as needed
newX = 80
newY = 25

' contrary to the docs the size is sent in a packed UINT
' the buffer must be one greater in both directions then the window
co = (newY * 65536) + (newX)

OPENCONSOLE
' get a handle to the consoles output buffer
handle = GetStdHandle(STD_OUTPUT_HANDLE)
IF(handle)
' Get the current console information
GetConsoleScreenBufferInfo(handle,cinfo)
' determine if the current buffer is larger then the one we want
' if so we need to set the window size FIRST. Otherwise set the buffer FIRST
oldY = cinfo.dwSize / 65536
oldX = cinfo.dwSize & 0x0000FFFF
IF(oldX * oldY) > (newX * newY)
' set the console window to encompass the new size
  sm.left = 0
  sm.top = 0
  sm.right = newX-1
  sm.bottom = newY-1
  SetConsoleWindowInfo(handle,1,sm)
' set the buffer size
  SetConsoleScreenBufferSize(handle,co)
ELSE
' set the buffer size
   SetConsoleScreenBufferSize(handle,co)
' set the console window to encompass the new size
   sm.left = 0
   sm.top = 0
   sm.right = newX-1
   sm.bottom = newY-1
   SetConsoleWindowInfo(handle,1,sm)
  ENDIF
ENDIF
PRINT USING("New console size: ##x##",newX,newY)
PRINT "Press any key to close"
DO:UNTIL INKEY$ <> ""
CLOSECONSOLE
END



best wishes, :)

Graham
Tomorrow may be too late ..