Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Console Properties

Is it possible to change the length and width of the console box to a size appropriate to my program, using delphi code??

cheers

Comments

  • netgertnetgert Member Posts: 331
    : Is it possible to change the length and width of the console box to a size appropriate to my program, using delphi code??
    :
    : cheers
    :

    This worked for me:
    [code]
    uses
    Windows;

    var
    sr: TSmallRect

    begin
    sr.Left := 0; // Didn't affect anything for me
    sr.Top := 0; // Didn't affect anything for me
    sr.Right := 49; // Width - 1
    sr.Bottom := 19; // Height - 1
    SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), True, sr);
    end;
    [/code]
    Note that this only changes the size of the console window in characters, but doesn't affect the buffer size of console, so a scrollbar will appear if resized to smaller size. You must set the buffer size to smaller size too, after window (only when result size is smaller)

    Also note that you can't size the window bigger unless you size the buffer bigger first.

    Check the return value for success (True) or failure (False)

    You can set the console buffer size with
    [code]
    var
    crd: TCoord;
    begin
    crd.X := 100; // Width
    crd.Y := 50; // Height
    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), crd);
    end;
    [/code]
    [hr][red][italic][b]N[/b][/red][blue]et[/blue][red][b]G[/b][/red][blue]ert[/italic][/blue][hr]

Sign In or Register to comment.