Consolen grösse
-
Hallo zusammen
Möchte mein Consolen Fenster auf grösse 1= höhe und 90 = breit setzen
aber bekomme von SetConsoleWindowInfo() immer 0 zurück. Das gleiche bei SetConsoleScreenBufferSize()
void setConsoleSize(short hight, short width) { HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); SMALL_RECT size = {0}; COORD b_size = {0}; BOOL rc = 0; size.Left = 0; size.Top = 0; size.Right = width; size.Bottom = hight; b_size.X = width+1; b_size.Y = hight+1; rc = SetConsoleWindowInfo(hCon, 1, &size); printf("GetLastError() fail %i",GetLastError()); rc = SetConsoleScreenBufferSize(hCon, b_size); printf("GetLastError() fail %i",GetLastError()); }
Was mache ich falsch?
-
Und was sagt GetLastError()?
Für eine Korrekte Anwendung siehe auch hier:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms685118In der Hilfe steht aber ausführlich drin, wann die Funktion schief geht:
The function fails if the specified window rectangle extends beyond the boundaries of the console screen buffer. This means that the Top and Left members of the lpConsoleWindow rectangle (or the calculated top and left coordinates, if bAbsolute is FALSE) cannot be less than zero. Similarly, the Bottom and Right members (or the calculated bottom and right coordinates) cannot be greater than (screen buffer height – 1) and (screen buffer width – 1), respectively. The function also fails if the Right member (or calculated right coordinate) is less than or equal to the Left member (or calculated left coordinate) or if the Bottom member (or calculated bottom coordinate) is less than or equal to the Top member (or calculated top coordinate).
-
void SetWindowExt(int x, int y) { SMALL_RECT sr_window = {0, 0, x - 1, y - 1}; COORD extension; CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); extension.X = max(x, csbi.dwMaximumWindowSize.X); extension.Y = max(y, csbi.dwMaximumWindowSize.Y); SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), extension); SetConsoleWindowInfo(GetStdHandle(STD_OUTPUT_HANDLE), TRUE, &sr_window); extension.X = x; extension.Y = y; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), extension); }
-
Danke habs selbst schon hinbekommen. Sieht eigentlich gleich aus wie Bellis Lösung.