如何在代码中增加控制台的大小 [英] How can I increase the size of the console inside the code

查看:119
本文介绍了如何在代码中增加控制台的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用lazarus IDE v1.8.4在pascal中编写一些代码,因为这个问题说我需要能够在代码中编辑控制台大小,所以我最好也需要获得他们可以拥有的最大控制台宽度.如果您知道如何使用,也请让我知道您的使用方式.谢谢!

I'm doing some code in pascal using lazarus IDE v1.8.4, as the question says I need to be able to edit the console size in the code, I also preferably need to get the max possible console width they can have. If you do know how please also let me know the uses you.. used. Thanks!

推荐答案

假设您的目标是Windows:

Assuming you're targeting Windows:

  • Use GetLargestConsoleWindowSize to retrieve the largest possible console size depending on the console font and display settings,

使用 SetConsoleScreenBufferSize 设置控制台屏幕缓冲区达到最大可能的大小

Use SetConsoleScreenBufferSize to set the console screen buffer to the largest possible size,

使用 SetConsoleWindowInfo 设置大小控制台窗口的位置和位置,以便默认情况下不会显示任何滚动条.

Use SetConsoleWindowInfo to set the size and position of the console's window, so that no scrollbars would be visible by default etc..

这时,控制台的窗口应位于您设置的位置.但是,在我的测试中,尽管窗口符合调整大小的要求,但位置却被忽略了.

At this point the console's window should be positioned as you've set. With my tests, however, while the window complies with the sizing request, the position is ignored.

在这种情况下,请使用任何API函数移动窗口,以下示例使用SetWindowPos.我必须声明 GetConsoleWindow ,因为它不是在拉撒路(Lazarus)中声明的1.6.

In that case use any API function to move the window, the below examples uses SetWindowPos. I had to declare GetConsoleWindow as it was not declared in Lazarus 1.6.


program Project1;

{$APPTYPE CONSOLE}

uses
  windows;

function GetConsoleWindow: HWND; stdcall external 'kernel32';

var
  Con: THandle;
  Size: TCoord;
  Rect: TSmallRect;
  Wnd: HWND;
begin
  Con := GetStdHandle(STD_OUTPUT_HANDLE);
  Size := GetLargestConsoleWindowSize(Con);

  SetConsoleScreenBufferSize(Con, Size);

  Rect.Left := -10;
  Rect.Top := -10;
  Rect.Right := Size.X - 11;
  Rect.Bottom := Size.Y - 11;
  SetConsoleWindowInfo(Con, True, Rect);

  Wnd := GetConsoleWindow;
  SetWindowPos(Wnd, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOZORDER);

  Readln;
end.


不要忘记添加错误检查.


And don't forget to add error checking.

这篇关于如何在代码中增加控制台的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆