Sign in to follow this  
Followers 0
MrKris1224

[SOLVED] Change window and console buffer size to specific size

8 posts in this topic

#1 ·  Posted (edited)

Hi, I writting console application but i have a problem. I want change window and console buffer size to specific size in columns and rows (chars and lines). I writed this code:

 

DllCall($vKernel, "bool", "SetConsoleScreenBufferSize", _
            "handle", $CONSOLE_OUTPUT, _
            "int", BitShift(50, -16) + 50)

It works but only changes buffer size and window doesn't change size.
I tryed this code too:

 

Local $tConsoleScreenBufferInfoEx = DllStructCreate($tagCONSOLE_SCREEN_BUFFER_INFOEX)
    DllCall($vKernel, "bool", "GetConsoleScreenBufferInfoEx", "handle", $CONSOLE_OUTPUT, "ptr", DllStructGetPtr($tConsoleScreenBufferInfoEx))
    DllStructSetData($tConsoleScreenBufferInfoEx, "MaximumWindowSizeX", 50)
    DllStructSetData($tConsoleScreenBufferInfoEx, "MaximumWindowSizeY", 50)
    DllCall($vKernel, "bool", "SetConsoleScreenBufferInfoEx", "handle", $CONSOLE_OUTPUT, "ptr", $tConsoleScreenBufferInfoEx)

But my application crashed. I don't know what's wrong in second code. Plz help.

Edited by Melba23
Reset title

Share this post


Link to post
Share on other sites



@ref

Share this post


Link to post
Share on other sites

Nobody knows how to do it?

Share this post


Link to post
Share on other sites

This might be what you're looking for:

https://msdn.microsoft.com/en-us/library/ms686125.aspx

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I tryed this function from Mat's Console UDF:

 

; #FUNCTION# ====================================================================================================================
; Name...........: _Console_SetWindowInfo
; Description ...: Sets the current size and position of a console screen buffer's window.
; Syntax.........: _Console_SetWindowInfo($hConsoleOutput, $iLeft, $iTop, $iRight, $iBottom [, $fAbsolute [, $hDll ]] )
; Parameters ....: $hConsoleOutput      - A handle to the console screen buffer. The handle must have the GENERIC_READ access
;                                         right.
;                  $iLeft               - The left edge of the buffer.
;                  $iTop                - The top edge of the buffer.
;                  $iRight              - The right edge of the buffer.
;                  $iBottom             - The top edge of the buffer.
;                  $fAbsolute           - If this parameter is TRUE (default), the coordinates specify the new upper-left and
;                                         lower-right corners of the window. If it is FALSE, the coordinates are relative to the
;                                         current window-corner coordinates.
;                  $hDll                - A handle to a dll to use. This prevents constant opening of the dll which could slow it
;                                         down. If you are calling lots of functions from the same dll then this recommended.
; Return values .: Success              - True
;                  Failure              - False
; Author ........: Matt Diesel (Mat)
; Modified.......:
; Remarks .......:
; Related .......: _Console_SetWindowPos
; Link ..........: http://msdn.microsoft.com/en-us/library/ms686125.aspx
; Example .......: No
; ===============================================================================================================================
Func _Console_SetWindowInfo($hConsoleOutput, $iLeft, $iTop, $iRight, $iBottom, $fAbsolute = True, $hDll = -1)
    Local $tConsoleWindow, $aResult

    If $hConsoleOutput = -1 Then $hConsoleOutput = _Console_GetStdHandle($STD_OUTPUT_HANDLE, $hDll)
    If $hDll = -1 Then $hDll = $__gvKernel32

    $tConsoleWindow = DllStructCreate($tagSMALL_RECT)
    DllStructSetData($tConsoleWindow, "Left", $iLeft)
    DllStructSetData($tConsoleWindow, "Top", $iTop)
    DllStructSetData($tConsoleWindow, "Right", $iRight)
    DllStructSetData($tConsoleWindow, "Bottom", $iBottom)

    $aResult = DllCall($hDll, "bool", "SetConsoleWindowInfo", _
            "handle", $hConsoleOutput, _
            "bool", $fAbsolute, _
            "ptr", DllStructGetPtr($tConsoleWindow))
    If @error Then Return SetError(@error, @extended, False)

    Return $aResult[0] <> 0
EndFunc   ;==>_Console_SetWindowInfo

But same as other codes - non result.

Share this post


Link to post
Share on other sites

I tryed this code in autoit but doesn't work:

 

Local $tConsoleWindow = DllStructCreate($tagSMALL_RECT)
    DllStructSetData($tConsoleWindow, "Left", 0)
    DllStructSetData($tConsoleWindow, "Top", 0)
    DllStructSetData($tConsoleWindow, "Right", $iWidth - 1)
    DllStructSetData($tConsoleWindow, "Bottom", $iHeight - 1)
    DllCall($vKernel, "bool", "SetConsoleWindowInfo", _
            "handle", $CONSOLE_OUTPUT, _
            "bool", True, _
            "ptr", DllStructGetPtr($tConsoleWindow))
    Local $tConsoleCOORD = DllStructCreate($tagCOORD)
    DllStructSetData($tConsoleCOORD, "X", $iWidth )
    DllStructSetData($tConsoleCOORD, "Y", $iHeight )
    DllCall($vKernel, "bool", "SetConsoleScreenBufferSize", _
            "handle", $CONSOLE_OUTPUT, _
            "ptr", DllStructGetPtr($tConsoleCOORD))

But same code in C++ works:

 

_COORD coord;
     coord.X = Width;
     coord.Y = Height;
     _SMALL_RECT Rect;
     Rect.Top = 0;
     Rect.Left = 0;
     Rect.Bottom = Height - 1;
     Rect.Right = Width - 1;
     HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);
     SetConsoleScreenBufferSize(Handle, coord);
     SetConsoleWindowInfo(Handle, TRUE, &Rect);


There's something wrong in autoit code?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@Edit

Solved...
 

Func _Console_SetSize($iWidth, $iHeight)
    Local $tConsoleWindow = DllStructCreate($tagSMALL_RECT)
    DllStructSetData($tConsoleWindow, "Left", 0)
    DllStructSetData($tConsoleWindow, "Top", 0)
    DllStructSetData($tConsoleWindow, "Right", $iWidth - 1)
    DllStructSetData($tConsoleWindow, "Bottom", $iHeight - 1)
    $aRet = DllCall($vKernel, "bool", "SetConsoleWindowInfo", _
            "handle", $CONSOLE_OUTPUT, _
            "bool", True, _
            "ptr", DllStructGetPtr($tConsoleWindow))
    DllCall($vKernel, "bool", "SetConsoleScreenBufferSize", _
            "handle", $CONSOLE_OUTPUT, _
            "int", BitShift($iHeight, -16) + $iWidth)
EndFunc

 

Edited by MrKris1224

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0