Originally Posted by
nowber
Hello! Suppose I draw a frame round the screen, using ascii table symbols and the next thing I want to do is printf different text, of course limiting the area, so that my text wouldn't be printed across these frame borders. Is it possible in C to tell to print everything within some limits? Surely gotoxy at each printf isn't the solution?
Sometimes, people ask "Why use that old Turbo C/C++ ?", and I just smile:
Code:
window Defines active text-mode window.
Syntax:
void window(int left, int top, int right, int bottom);
The top left corner of the screen is (1,1).
Prototype in:
conio.h
Remarks:
window defines a text window onscreen. If the coordinates are in any way
invalid, the call to window is ignored.
þ left and top are the screen coordinates
of the upper left corner of the window.
þ right and bottom are the screen
coordinates of the lower right corner.
The minimum size of the text window is one
column by one line. The default window is
full screen, with these coordinates:
þ 80-column mode: 1,1,80,25
þ 40-column mode: 1,1,40,25
Return Value: None.
Portability:
window works with IBM PCs and compatibles only.
A corresponding function exists in Turbo Pascal.
See Also:
clreol delline gotoxy puttext
clrscr gettextinfo insline textmode
Example:
#include <conio.h>
int main(void)
{
window(10,10,40,11);
textcolor(BLACK);
textbackground(WHITE);
cprintf("This is a test\r\n");
return 0;
}
Note that Turbo C ver. 1.01 had "int main()", before K&R's "The C Programming Language".
Lacking conio.h's help, you can still print inside a window, just as you can print up any columns, in C.
You just need variables for things like lmargin, rmargin, toprow, botrow, to define the left margin, right margin, top row, bottom row, etc.
So in a function, you send it the address of your char array you want printed, and it will handle it from there. It's not as nice as window, but it can be done easily.