Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incease the buffer size of the cmd window
#1
I wonder whether there exists a QM macro - or at least an idea - about increasing the size of the cmd window. Many thanks in advance.
#2
this is working for me
Tested on windows 7

Function SetConsuleBufferWindowSize
Code:
Copy      Help
int w
run "$system$\cmd.exe" "" "" "*" 0x10800 win("" "ConsoleWindowClass") w

int hwnd
if(!hwnd) hwnd=w; if(!hwnd) ret
if(!GetWindowThreadProcessId(hwnd &_i)) ret
lock
FreeConsole
if(!AttachConsole(_i)) ret

CONSOLE_SCREEN_BUFFER_INFOEX consolesize

consolesize.cbSize=sizeof(consolesize)

int hConsole = GetStdHandle(STD_OUTPUT_HANDLE)

GetConsoleScreenBufferInfoEx(hConsole &consolesize)

;note Screen Buffer Size width must be => than Window Size width for it to resize properly
COORD c
c.X = 100;;Screen Buffer Size width
c.Y = 40;;Screen Buffer Size height
consolesize.dwSize = c;
consolesize.srWindow.Left = 0
consolesize.srWindow.Right = 100;;Window Size width
consolesize.srWindow.Top = 0
consolesize.srWindow.Bottom = 40;;Window Size height
consolesize.dwMaximumWindowSize = c;
SetConsoleScreenBufferInfoEx(hConsole &consolesize)

FreeConsole


Note on windows 10 i don't need this at all can directly resize window using siz function or max for full size window.

@ Gintaras please correct any mistakes you see
#3
Dear Kevin, thank you very much for your ingenious advice. I am afraid I failed to run it (Win XP), with message :
Error in C:\Program Files\Quick Macros 2\winapi.txt: function not found
on function :
GetConsoleScreenBufferInfoEx

I attach herewith a .png file with a screen shot. I would appreciate it if you could advice me. Best regards.


Attached Files Image(s)
   
#4
Probably will need to drop the EX from the windows functions and adjust parameters or declare the functions first

Try to add declaration at beginning 
 and see if it works  if not will need to come up with a solution for windows xp

Code:
Copy      Help
dll kernel32 #GetConsoleScreenBufferInfoEx hConsoleOutput CONSOLE_SCREEN_BUFFER_INFOEX*lpConsoleScreenBufferInfoEx
#5
cant test on xp but try this uses older WinApi functions(win2000) works on win7 as well

Function SetConsuleBufferWindowSize2
Code:
Copy      Help
int w
run "$system$\cmd.exe" "" "" "*" 0x10800 win("" "ConsoleWindowClass") w

int hwnd
if(!hwnd) hwnd=w; if(!hwnd) ret
if(!GetWindowThreadProcessId(hwnd &_i)) ret
lock
FreeConsole
if(!AttachConsole(_i)) ret

int hConsole = GetStdHandle(STD_OUTPUT_HANDLE)

CONSOLE_SCREEN_BUFFER_INFO scbi

GetConsoleScreenBufferInfo(hConsole &scbi)

COORD dwsize
dwsize.X = 100
dwsize.Y = 40
SetConsoleScreenBufferSize(hConsole dwsize)
scbi.srWindow.Bottom = 40
scbi.srWindow.Right = 100
scbi.srWindow.Left = 0
scbi.srWindow.Top = 0

SMALL_RECT srctWindow
srctWindow=scbi.srWindow
SetConsoleWindowInfo(hConsole TRUE &srctWindow)
FreeConsole
max w
#6
Dear Kevin, I have tested it, it works perfectly. Your contribution is invaluable. Best regards.
#7
s
I redid SetConsuleBufferWindowSize2 slightly. Made it easier to resize. Only need to change width and height at the beginning now. Also fixed small bug in resizing cmd window, window dimensions need to be smaller than buffer when resizing even though will be same dimensions after.

ssimop i have been meaning to post this update but forgot till now

Function SetConsuleBufferWindowSize2a
Code:
Copy      Help
int width height w hwnd
width = 100;; console width is in colums
height = 40;;console height is in rows

;run "$system$\cmd.exe" "" "" "C:\" 16|0x10000 win("" "ConsoleWindowClass") w ;; use this if you want to run hidden while you resize console
run "$system$\cmd.exe" "" "" "*" 0x10800 win("" "ConsoleWindowClass") w

if(!hwnd) hwnd=w; if(!hwnd) ret
if(!GetWindowThreadProcessId(hwnd &_i)) ret
lock
FreeConsole
if(!AttachConsole(_i)) ret

int hConsole = GetStdHandle(STD_OUTPUT_HANDLE)

CONSOLE_SCREEN_BUFFER_INFO scbi

GetConsoleScreenBufferInfo(hConsole &scbi)

COORD dwsize
dwsize.X = width
dwsize.Y = height
SetConsoleScreenBufferSize(hConsole dwsize)
scbi.srWindow.Bottom = height-1
scbi.srWindow.Right = width-1
scbi.srWindow.Left = 0
scbi.srWindow.Top = 0

SMALL_RECT srctWindow
srctWindow=scbi.srWindow
SetConsoleWindowInfo(hConsole TRUE &srctWindow)
FreeConsole
;hid- w ;;; use this if you run console hidden to show resized
;act w


Forum Jump:


Users browsing this thread: 4 Guest(s)