Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { Autor : Tiago Portela
- Email : sapitando@gmail.com
- Sobre o programa : Muda o tamanho da janela do console do Windows, a largura(variável Cols) tem que ser maior ou igual a 14,
- fiz o teste apenas no windows 7.
- Obs. : Apenas tentando aprender algorítimos, sozinho, por hobby. }
- program Resize_Console_Window;
- uses JwaWindows, Crt;
- var
- Cols, Lines : SHORT;
- SysMenuButtons : boolean;
- TitleWindow : PChar;
- WindowError : BOOL;
- function SetConsoleWindowInfoAndBufferSize(X, Y : SHORT;
- B : boolean; TW : PChar) : BOOL;
- var
- hConsoleOutput : HANDLE;
- dwSize : COORD;
- lpCW : SMALL_RECT = (Left : 0; Top : 0);
- begin
- if (not (MoveWindow(GetConsoleWindow, 0, 0, 1, 1, TRUE)))
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 1;
- exit;
- end;
- if (not (SetConsoleTitle(TW)))
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 2;
- exit;
- end;
- if (not (B))
- then begin
- if (SetWindowLong(GetConsoleWindow, GWL_STYLE,
- GetWindowLong(GetConsoleWindow, GWL_STYLE) and
- (not (WS_SYSMENU or WS_HSCROLL or WS_VSCROLL))) = 0)
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 3;
- exit;
- end;
- end;
- hConsoleOutput := GetStdHandle(STD_OUTPUT_HANDLE);
- if (hConsoleOutput = INVALID_HANDLE_VALUE)
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 4;
- exit;
- end;
- dwSize := GetLargestConsoleWindowSize(hConsoleOutput);
- if (X > dwSize.X)
- then X := dwSize.X;
- if (Y > dwSize.Y)
- then Y := dwSize.Y;
- dwSize.X := X;
- dwSize.Y := Y;
- if (not (SetConsoleScreenBufferSize(hConsoleOutput, dwSize)))
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 5;
- exit;
- end;
- lpCW.Right := X - 1;
- lpCW.Bottom := Y - 1;
- if (not (SetConsoleWindowInfo(hConsoleOutput, TRUE, lpCW)))
- then begin
- INT(SetConsoleWindowInfoAndBufferSize) := 6;
- exit;
- end;
- window(1, 1, X, Y);
- INT(SetConsoleWindowInfoAndBufferSize) := 0;
- end;
- begin
- Cols := 40;
- Lines := 20;
- SysMenuButtons := FALSE;
- TitleWindow := 'My Window';
- WindowError := SetConsoleWindowInfoAndBufferSize(Cols, Lines,
- SysMenuButtons, TitleWindow);
- if WindowError
- then writeln(INT(WindowError));
- textbackground(red);
- clrscr;
- readln;
- end.
Add Comment
Please, Sign In to add comment