Windows SetConsoleScreenBufferSize() returning an odd error code

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Oct 5 04:24:32 PDT 2013


On 10/5/13, webwraith <webwraith at fastmail.fm> wrote:
> Could someone give this code the quick once over and tell me
> where I'm going wrong, or simply how to get this to work?

In the docs:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686044%28v=vs.85%29.aspx

It says:

dwSize [in]

    A COORD structure that specifies the new size of the console
screen buffer, in character rows and columns. The specified width and
height cannot be less than the width and height of the console screen
buffer's window.
**The specified dimensions also cannot be less than the minimum size
allowed by the system.  This minimum depends on the current font size
for the console (selected by the user) and the SM_CXMIN and SM_CYMIN
values returned by the GetSystemMetrics function.**

So you need to make these calls:

-----
short width  = cast(short)(csbi.srWindow.Right - csbi.srWindow.Left);
short height = cast(short)(csbi.srWindow.Bottom - csbi.srWindow.Top);

auto minX = GetSystemMetrics(SM_CXMIN);
auto minY = GetSystemMetrics(SM_CYMIN);

c.X = cast(short)max(minX, width);
c.Y = cast(short)max(minY, height);
-----

Also make sure to import std.algorithm to use the max() function.


More information about the Digitalmars-d-learn mailing list