Salut,
Si tu parles d'une console sous Windows, alors tu peux employer le petit programme suivant :
#include <windows.h>
BOOL SetConsoleSizeXY(HANDLE hStdout, int iWidth, int iHeight)
{
CONSOLE_SCREEN_BUFFER_INFO info;
COORD coordMax;
coordMax = GetLargestConsoleWindowSize(hStdout);
if (iHeight > coordMax.Y) iHeight = coordMax.Y;
if (iWidth > coordMax.X) iWidth = coordMax.X;
if (!GetConsoleScreenBufferInfo(hStdout, &info)) return FALSE;
/* - hauteur - */
info.srWindow.Left = 0;
info.srWindow.Right = info.dwSize.X - 1;
info.srWindow.Top = 0;
info.srWindow.Bottom = iHeight - 1;
if (iHeight < info.dwSize.Y)
{
if (!SetConsoleWindowInfo(hStdout, TRUE, &info.srWindow))
return FALSE;
info.dwSize.Y = iHeight;
if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
return FALSE;
}
else if (iHeight > info.dwSize.Y)
{
info.dwSize.Y = iHeight;
if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
return FALSE;
if (!SetConsoleWindowInfo(hStdout, TRUE, &info.srWindow))
return FALSE;
}
if (!GetConsoleScreenBufferInfo(hStdout, &info))
return FALSE;
/* --- largeur - */
info.srWindow.Left = 0;
info.srWindow.Right = iWidth - 1;
info.srWindow.Top = 0;
info.srWindow.Bottom = info.dwSize.Y - 1;
if (iWidth < info.dwSize.X)
{
if (!SetConsoleWindowInfo(hStdout, TRUE, &info.srWindow))
return FALSE;
info.dwSize.X = iWidth;
if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
return FALSE;
}
else if (iWidth > info.dwSize.X)
{
info.dwSize.X = iWidth;
if (!SetConsoleScreenBufferSize(hStdout, info.dwSize))
return FALSE;
if (!SetConsoleWindowInfo(hStdout, TRUE, &info.srWindow))
return FALSE;
}
return TRUE;
}
int main(int argc, char** argv)
{
CONSOLE_SCREEN_BUFFER_INFO info;
HANDLE hStdout;
hStdout = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleSizeXY(hStdout, 24, 12);
system("pause");
return 0;
}
Il ne fait, bien sûr, rien. Seule la fonction SetConsoleSizeXY permet de définir la taille de la console MS-DOS dans ton Windows.
Il ne te reste plus qu'à gérer, au besoin, les questions des barres de défilement et de taille du buffer.
En espérant t'avoir aidé,
A plus tard.
NB. Si tu veux entrer plus en profondeur dans ce thème, les API Windows en mode console...