SetConsoleWindowInfo() schlägt fehl
-
Hallo allerseits
Habe ein Problem beim verändern des Consolen Fenters. Und zwar gibt mir GetLastError immer 87 zurück. Das heisst ja das die Parameter invalid sind, aber das kann ich mir nicht vorstellen. Hier der Code.
void SetConsole(short hight, short width, wchar_t *title) { SMALL_RECT size={0}; COORD b_size={0}; HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); size.Left = 0; size.Top = 0; size.Right = width; size.Bottom = hight; b_size.X = width+1; b_size.Y = hight+1; SetConsoleWindowInfo(hCon, 1, &size); printf_s("setconsoleinfo error %i",GetLastError()); // Hier immer 87 == Parameter invalid ??? SetConsoleScreenBufferSize(hCon, b_size); SetConsoleTitleW(title); }Danke schonmal für eure Hilfe!
-
MSDN schrieb:
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).
Könnte das die Ursache sein? (bzw. was für Werte übergibst du an deine Funktion?)
-
zbsp. 40 höhe und 120 breite?
-
ist das Handle hCon auch gültig? bzw schon mal geprüft?
-
Ja ist es. Wenn ich die funktion mit zbsp. 1 breite und 1 höhe angebe funktioniert es!
-
alf00 schrieb:
zbsp. 40 höhe und 120 breite?
Den Wert solltest du mal mit dem vergleichen, den GetConsoleScreenBufferInfo() dir liefert:
void GetConsole() { CONSOLE_SCREEN_BUFFER_INFO info = {}; HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hcon, &info); cout << "Screen Size: "<<info.dwSize.x<<"*"<<info.dwSize.y<<endl; }
-
Und was sagt GetLastError?
-
Das kann mann dem ersten Posr entnehmen!
-
MSDN sagt :
"If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError."
Es fehlt allerdings CloseHandle am Ende.