Text User Interface
Windows, menus and shadows in DOS text mode
Part 4 of 9 · Early Work
In 1998 I wanted my school projects to look like Borland’s own DOS tools, so I wrote the windowing system myself: overlapping windows with z-order and shadows, resizing and moving, menus, and common dialogs, all in 80 by 25 text mode with Borland C/C++ 3.0.

Just as it worked, I got a telephone line, found the Internet, and learned that Borland had already written one, Turbo Vision, and had made it free the year before. I was disappointed for about a week. Then I kept using mine, in nearly every project for the rest of my degree, and what it taught me about how a user interface actually works (redrawing, focus, what a window owes the windows under it) was worth more than the time.
Reading it again
Officially, the course projects built on it belonged to Team 14 (Equipo No. 14). In practice, as on every school team I was on, I wrote all of it, the library and the projects.
Two pieces of it I still respect. Moving a window redraws only the part of the old background
that the new position doesn’t cover, builds the new saved background from the overlap plus
fresh screen bytes, and allocates its memory before touching any state, so a failed move leaves
nothing half done. Bringing a window to the top composes the whole screen in a 4,000-byte copy
in memory and blits it once, so nothing flickers, and if that memory isn’t there it draws
straight to the screen instead. The API speaks Windows, too: WS_ window styles, SW_ show
commands, MB_ message boxes, and menus declared as data along with their status-bar help.
The worst part is how it was shared. There is no library to link: each project folder carries
its own copy of VENTANAS.CPP (ventanas means “windows”), about 1,800 lines of window
manager three times over, with each project’s own code mixed into its copy (in one of them, a
1,034-line menu handler). Fixes only flowed forward, so the later copies have mouse and keyboard
fixes the earlier ones never got. Today it would be one library, with callbacks, in one
repository. Then, each project was a folder I handed in on a floppy, and copying the folder
was my version control.
I also wrote my own strlen, strcpy and strcmp, under the C library’s names but with
other meanings: my strlen skips the & that marks a menu shortcut, and my strcmp only
says equal or not. Which one a call got depended on where in the file it sat.
The trees project has the bugs a demo never shows. Unit prices reuse a variable from the invoice total, so a price of 10.50 prints as “105.0”. Dates pad the day with a zero by testing the month, so the 15th of January prints as “01”. And the menu item Borrar, “delete a client from the binary tree”, is grayed out for good, with no code behind it. Deleting from a binary search tree was the hard part of that course.
For 1998, what strikes me is where its shape came from. I hadn’t seen Turbo Vision, so I copied the system I had seen, Windows: styles, show commands, message boxes, menus with their help in a status bar. I was learning one platform’s ideas by building them on another, which taught me more than using either. What strikes me the other way is the copying. Version control was already free, in RCS and CVS, but I had never heard of either, and a floppy was the only repository I knew.
Downloads: four course projects built on it, with source: two field editors, a stack and queue visualizer, and a tree visualizer.
Source and history on GitHub: Kronuz/TUI, with the four projects unpacked.